PluginProbe
HyperPay Payments / trunk
HyperPay Payments vtrunk
6.6.0 trunk 1.7 1.8 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.1.0 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.5 4.0.0 4.0.2 All 34 releases
hyperpay-gateways / src / assets / js / Helpers.js

Helpers.js in HyperPay Payments trunk, at src/assets/js/Helpers.js

92 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import axios from "axios";
2 import { paymentAuthorized, updateContact, updateShippingMethod } from "./dispatcher";
3
4
5
6 export const useFetch = (url) => {
7
8 const content_type = url == "hyperpay_process_checkout" ? "application/x-www-form-urlencoded" : "multipart/form-data"
9
10 const instance = axios.create({
11 baseURL: `/?wc-ajax=${url}`,
12 withCredentials: true,
13 headers: {
14 "Content-Type": content_type
15 }
16 });
17
18 return instance
19 }
20
21 export const raiseError = (props, message = null, Json = true) => {
22
23 if (Json) {
24 props.onError(message ?? "could not create order")
25 } else {
26 const container = document.querySelector('.wc-block-components-notices')
27 container.innerHTML = message;
28 }
29
30 return { status: "ABORT" }
31 }
32
33 /**
34 *
35 * @param {dispatcher} dispatcher
36 * @param {string} checkoutId
37 * @param {object} shippingMethod
38 * @returns
39 */
40 export const generateOptions = (props, shippingMethod, checkoutId) => {
41
42 return {
43
44 applePay: {
45 version: "3",
46 buttonType: props.setting.extraScriptData.action_type,
47 buttonStyle: props.setting.extraScriptData.action_style,
48 requiredBillingContactFields: ['postalAddress', 'email', "phone"],
49 requiredShippingContactFields: ['postalAddress', 'email', "phone"],
50 currencyCode: props.billing.currency.code,
51 onCancel: props.onClose,
52 total: {
53 label: "By HyperPay",
54 amount: (props.billing.cartTotal.value ?? 0) / (10 ** props.billing.currency.minorUnit ?? 0)
55 },
56 onShippingMethodSelected: async function (shipping_method) {
57 return updateShippingMethod(props, shippingMethod, shipping_method)
58 },
59 onPaymentAuthorized: async function (payment) {
60 return paymentAuthorized(props, shippingMethod, payment, checkoutId)
61 },
62 onShippingContactSelected: async function (shippingContact) {
63 return updateContact(props, shippingContact)
64 },
65 },
66
67 }
68 }
69
70 export const paymentResult = (props, response) => {
71
72 if (response.data.result != "success")
73 return raiseError(props, response.data.result)
74 return {
75 newTotal: response.data.total,
76 newLineItems: response.data.displayItems,
77 newShippingMethods: response.data.shipping_options
78 }
79 }
80
81 export const clearUpCopyAndPay = () => {
82 if (window.wpwl !== undefined && window.wpwl.unload !== undefined) {
83 window.wpwl.unload();
84 document.querySelectorAll("script").forEach(i => {
85 if (i.src.includes('static.min.js') || i.src.includes('paymentWidgets.js')) {
86 i.remove()
87 }
88 })
89 }
90 }
91
92