@sikka/hawa 0.0.2 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/hawa-publish-push.yml +45 -0
- package/.github/workflows/hawa-publish.yml +45 -0
- package/.prettierrc +28 -28
- package/README.md +149 -148
- package/es/index.es.js +1 -0
- package/lib/index.js +1 -0
- package/package.json +62 -47
- package/rollup.config.js +30 -30
- package/src/Assets/images/card-background/1.jpeg +0 -0
- package/src/Assets/images/card-background/10.jpeg +0 -0
- package/src/Assets/images/card-background/11.jpeg +0 -0
- package/src/Assets/images/card-background/12.jpeg +0 -0
- package/src/Assets/images/card-background/13.jpeg +0 -0
- package/src/Assets/images/card-background/14.jpeg +0 -0
- package/src/Assets/images/card-background/15.jpeg +0 -0
- package/src/Assets/images/card-background/16.jpeg +0 -0
- package/src/Assets/images/card-background/17.jpeg +0 -0
- package/src/Assets/images/card-background/18.jpeg +0 -0
- package/src/Assets/images/card-background/19.jpeg +0 -0
- package/src/Assets/images/card-background/2.jpeg +0 -0
- package/src/Assets/images/card-background/20.jpeg +0 -0
- package/src/Assets/images/card-background/21.jpeg +0 -0
- package/src/Assets/images/card-background/22.jpeg +0 -0
- package/src/Assets/images/card-background/23.jpeg +0 -0
- package/src/Assets/images/card-background/24.jpeg +0 -0
- package/src/Assets/images/card-background/25.jpeg +0 -0
- package/src/Assets/images/card-background/3.jpeg +0 -0
- package/src/Assets/images/card-background/4.jpeg +0 -0
- package/src/Assets/images/card-background/5.jpeg +0 -0
- package/src/Assets/images/card-background/6.jpeg +0 -0
- package/src/Assets/images/card-background/7.jpeg +0 -0
- package/src/Assets/images/card-background/8.jpeg +0 -0
- package/src/Assets/images/card-background/9.jpeg +0 -0
- package/src/Assets/images/card-type/amex.png +0 -0
- package/src/Assets/images/card-type/diners.png +0 -0
- package/src/Assets/images/card-type/discover.png +0 -0
- package/src/Assets/images/card-type/mastercard.png +0 -0
- package/src/Assets/images/card-type/troy.png +0 -0
- package/src/Assets/images/card-type/unionpay.png +0 -0
- package/src/Assets/images/card-type/visa.png +0 -0
- package/src/blocks/Account/UserProfile.js +15 -0
- package/src/blocks/Account/UserSettings.js +15 -0
- package/src/blocks/Account/index.js +2 -0
- package/src/blocks/AuthForms/NewPasswordForm.js +24 -0
- package/src/blocks/AuthForms/ResetPasswordForm.js +13 -0
- package/src/blocks/AuthForms/SignInForm.js +55 -0
- package/src/blocks/AuthForms/SignUpForm.js +68 -0
- package/src/{components/Hawa → blocks}/AuthForms/index.js +4 -4
- package/src/blocks/Payment/CreditCardForm.js +31 -0
- package/src/blocks/Payment/Form/CForm.js +328 -0
- package/src/blocks/Payment/Form/Card.js +242 -0
- package/src/blocks/Payment/Gateway/GooglePay.js +251 -0
- package/src/blocks/Payment/Gateway/Payfort.js +90 -0
- package/src/blocks/Payment/Gateway/Paypal.js +138 -0
- package/src/blocks/Payment/Gateway/Wallet.js +149 -0
- package/src/blocks/Payment/PaymentMethod.js +132 -0
- package/src/blocks/Payment/SelectPayment.js +95 -0
- package/src/blocks/Payment/index.js +16 -0
- package/src/index.js +4 -1
- package/src/layout/Box.js +39 -0
- package/src/layout/index.js +1 -0
- package/src/stories/ActionButton.stories.js +53 -0
- package/src/stories/AdaptiveButton.stories.js +80 -80
- package/src/stories/Alert.stories.js +41 -48
- package/src/stories/BlocksStories/AuthForm.stories.js +99 -0
- package/src/stories/BlocksStories/PaymentForm.stories.js +111 -0
- package/src/stories/BlocksStories/UserAccount.stories.js +46 -0
- package/src/stories/CheckBox.stories.js +35 -34
- package/src/stories/GlobalVariables.stories.js +44 -108
- package/src/stories/HawaProvider.stories.js +22 -23
- package/src/stories/InputLabel.stories.js +92 -100
- package/src/stories/Introduction.stories.js +211 -0
- package/src/stories/LayoutStories/Box.stories.js +56 -0
- package/src/stories/RadioSelector.stories.js +69 -69
- package/src/stories/TextField.stories.js +50 -50
- package/src/styles.css +400 -400
- package/src/styles.scss +679 -0
- package/src/themes/HawaProvider.js +87 -0
- package/src/ui/ActionButton.js +40 -0
- package/src/{components/Hawa/AdaptiveButton → ui}/AdaptiveButton.js +252 -254
- package/src/ui/ApplePayButton.js +94 -0
- package/src/{components/Hawa/AutoCompleteField/AutoCompleteField.jsx → ui/AutoCompleteField.js} +32 -33
- package/src/{components/Hawa/Checkbox/Checkbox.jsx → ui/Checkbox.js} +21 -20
- package/src/{components/Hawa/DragDropImages/DragDropImages.jsx → ui/DragDropImages.js} +180 -180
- package/src/ui/GithubButton.js +91 -0
- package/src/ui/GoogleButton.js +83 -0
- package/src/ui/GooglePayButton.js +94 -0
- package/src/{components/Hawa/Hawa.jsx → ui/Hawa.js} +3 -3
- package/src/ui/HawaInputLabel.js +33 -0
- package/src/{components/Hawa/TextArea/TextArea.jsx → ui/HawaTextArea.js} +38 -38
- package/src/ui/HawaTextField.js +118 -0
- package/src/ui/MadaButton.js +94 -0
- package/src/ui/PayPalButton.js +94 -0
- package/src/{components/Hawa/RadioBox/RadioBox.jsx → ui/RadioBox.js} +29 -29
- package/src/{components/Hawa/RadioSelector/RadioSelector.jsx → ui/RadioSelector.js} +51 -51
- package/src/{components/Hawa/Row/Row.jsx → ui/Row.js} +21 -21
- package/src/ui/STCPayButton.js +94 -0
- package/src/{components/Hawa/SelectedField/SelectedField.jsx → ui/SelectedField.js} +46 -46
- package/src/ui/StyledAlert.js +30 -0
- package/src/{components/Hawa/StyledTooltip → ui}/StyledTooltip.js +46 -46
- package/src/{components/Hawa/TabPanel/TabPanel.jsx → ui/TabPanel.js} +37 -37
- package/src/ui/TwitterButton.js +84 -0
- package/src/ui/VisaMasterButton.js +94 -0
- package/src/ui/WalletButton.js +91 -0
- package/src/ui/index.js +22 -0
- package/src/util.js +20 -20
- package/storybook-static/0.54f7e52e.iframe.bundle.js +1 -0
- package/storybook-static/0.f47eb24a4893a96ec307.manager.bundle.js +1 -0
- package/storybook-static/1.95be85dd.iframe.bundle.js +3 -0
- package/storybook-static/{1.7c0dc86d.iframe.bundle.js.LICENSE.txt → 1.95be85dd.iframe.bundle.js.LICENSE.txt} +0 -0
- package/storybook-static/1.95be85dd.iframe.bundle.js.map +1 -0
- package/storybook-static/2.eb601582.iframe.bundle.js +1 -0
- package/storybook-static/{3.592ce28f.iframe.bundle.js → 3.d72f7fac.iframe.bundle.js} +0 -0
- package/storybook-static/4.0fcda1281dc1961dbe94.manager.bundle.js +2 -0
- package/storybook-static/{5.f459d151315e6780c20f.manager.bundle.js.LICENSE.txt → 4.0fcda1281dc1961dbe94.manager.bundle.js.LICENSE.txt} +0 -0
- package/storybook-static/5.63ab4f94d50a3acf080d.manager.bundle.js +1 -0
- package/storybook-static/6.a6d45262f7e98f3f18d3.manager.bundle.js +2 -0
- package/storybook-static/{11.f4e922583ae35da460f3.manager.bundle.js.LICENSE.txt → 6.a6d45262f7e98f3f18d3.manager.bundle.js.LICENSE.txt} +0 -0
- package/storybook-static/{7.3d04765dbf3f1dcd706c.manager.bundle.js → 7.097710753af9a1c41b80.manager.bundle.js} +1 -1
- package/storybook-static/7.ffb0d84b.iframe.bundle.js +1 -0
- package/storybook-static/{8.8e2132ec.iframe.bundle.js → 8.68cd1217.iframe.bundle.js} +2 -2
- package/storybook-static/{8.8e2132ec.iframe.bundle.js.LICENSE.txt → 8.68cd1217.iframe.bundle.js.LICENSE.txt} +0 -0
- package/storybook-static/8.68cd1217.iframe.bundle.js.map +1 -0
- package/storybook-static/8.76c3cbf398692028e834.manager.bundle.js +1 -0
- package/storybook-static/{9.109ea555.iframe.bundle.js → 9.488e3969.iframe.bundle.js} +0 -0
- package/storybook-static/iframe.html +2 -2
- package/storybook-static/index.html +9 -1
- package/storybook-static/main.044648aa.iframe.bundle.js +1 -0
- package/storybook-static/main.ac6e4b72b033097dad76.manager.bundle.js +1 -0
- package/storybook-static/{runtime~main.ffc8677e.iframe.bundle.js → runtime~main.3e280e98.iframe.bundle.js} +1 -1
- package/storybook-static/runtime~main.c8dac23bc753439736f0.manager.bundle.js +1 -0
- package/storybook-static/vendors~main.a697e07137d366f95f76.manager.bundle.js +2 -0
- package/storybook-static/{vendors~main.a935f15a2179a6eff5fd.manager.bundle.js.LICENSE.txt → vendors~main.a697e07137d366f95f76.manager.bundle.js.LICENSE.txt} +6 -12
- package/storybook-static/vendors~main.d75dc38b.iframe.bundle.js +76 -0
- package/storybook-static/{vendors~main.4aa936b1.iframe.bundle.js.LICENSE.txt → vendors~main.d75dc38b.iframe.bundle.js.LICENSE.txt} +3 -45
- package/storybook-static/vendors~main.d75dc38b.iframe.bundle.js.map +1 -0
- package/tools/build-styles.js +17 -0
- package/dist/index.es.js +0 -37
- package/dist/index.js +0 -37
- package/src/components/Hawa/AdaptiveButton/index.js +0 -1
- package/src/components/Hawa/AuthForms/NewPasswordForm.js +0 -23
- package/src/components/Hawa/AuthForms/ResetPasswordForm.js +0 -21
- package/src/components/Hawa/AuthForms/SignInForm.js +0 -25
- package/src/components/Hawa/AuthForms/SignUpForm.js +0 -26
- package/src/components/Hawa/AuthForms/viaFacebook.js +0 -0
- package/src/components/Hawa/AuthForms/viaGithub.js +0 -0
- package/src/components/Hawa/AuthForms/viaGoogle.js +0 -0
- package/src/components/Hawa/AuthForms/viaTwitter.js +0 -0
- package/src/components/Hawa/AutoCompleteField/index.js +0 -1
- package/src/components/Hawa/Box/Box.js +0 -18
- package/src/components/Hawa/Box/index.js +0 -1
- package/src/components/Hawa/Checkbox/index.js +0 -1
- package/src/components/Hawa/DragDropImages/index.js +0 -1
- package/src/components/Hawa/HawaProvider/HawaProvider.js +0 -19
- package/src/components/Hawa/HawaProvider/index.js +0 -1
- package/src/components/Hawa/InputLabel/StyledInputLabel.js +0 -15
- package/src/components/Hawa/InputLabel/index.js +0 -1
- package/src/components/Hawa/RadioBox/index.js +0 -1
- package/src/components/Hawa/RadioSelector/index.js +0 -1
- package/src/components/Hawa/Row/index.js +0 -1
- package/src/components/Hawa/SelectedField/index.js +0 -1
- package/src/components/Hawa/StyledAlert/StyledAlert.js +0 -15
- package/src/components/Hawa/StyledAlert/index.js +0 -1
- package/src/components/Hawa/StyledTooltip/index.js +0 -1
- package/src/components/Hawa/TabPanel/index.js +0 -1
- package/src/components/Hawa/TextArea/index.js +0 -1
- package/src/components/Hawa/TextField/TextField.js +0 -54
- package/src/components/Hawa/TextField/index.js +0 -1
- package/src/components/Hawa/index.js +0 -10
- package/src/stories/AuthForm.stories.js +0 -76
- package/src/stories/Box.stories.js +0 -45
- package/storybook-static/0.12392f0b.iframe.bundle.js +0 -1
- package/storybook-static/0.55b012452099ace2dca6.manager.bundle.js +0 -1
- package/storybook-static/1.0f38715c61c7c3cd11db.manager.bundle.js +0 -1
- package/storybook-static/1.7c0dc86d.iframe.bundle.js +0 -3
- package/storybook-static/1.7c0dc86d.iframe.bundle.js.map +0 -1
- package/storybook-static/10.9f2923a7561bc20fffdb.manager.bundle.js +0 -1
- package/storybook-static/11.f4e922583ae35da460f3.manager.bundle.js +0 -2
- package/storybook-static/12.1415460941f0bdcb8fa8.manager.bundle.js +0 -1
- package/storybook-static/2.ee357266.iframe.bundle.js +0 -1
- package/storybook-static/5.f459d151315e6780c20f.manager.bundle.js +0 -2
- package/storybook-static/6.3bd64d820f3745f262ff.manager.bundle.js +0 -1
- package/storybook-static/7.af56919f.iframe.bundle.js +0 -1
- package/storybook-static/8.8e2132ec.iframe.bundle.js.map +0 -1
- package/storybook-static/8.b541eadfcb9164835dfc.manager.bundle.js +0 -1
- package/storybook-static/9.411ac8e451bbb10926c7.manager.bundle.js +0 -1
- package/storybook-static/main.78b7d418.iframe.bundle.js +0 -1
- package/storybook-static/main.9bb085ebb152f5b19a2a.manager.bundle.js +0 -1
- package/storybook-static/runtime~main.9468098d21070636985f.manager.bundle.js +0 -1
- package/storybook-static/vendors~main.4aa936b1.iframe.bundle.js +0 -3
- package/storybook-static/vendors~main.4aa936b1.iframe.bundle.js.map +0 -1
- package/storybook-static/vendors~main.a935f15a2179a6eff5fd.manager.bundle.js +0 -2
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import qs from "qs";
|
|
3
|
+
import { useRouter } from "next/router";
|
|
4
|
+
import { useState, useEffect } from "react";
|
|
5
|
+
import useTranslation from "next-translate/useTranslation";
|
|
6
|
+
import Script from "next/script";
|
|
7
|
+
|
|
8
|
+
const GooglePay = (props) => {
|
|
9
|
+
const transaction = props.currenttransactiongpay;
|
|
10
|
+
const router = useRouter();
|
|
11
|
+
console.log("transaction=", transaction);
|
|
12
|
+
const { t, lang } = useTranslation("common");
|
|
13
|
+
const [googlepayloaded, setGooglePayLoaded] = useState(false);
|
|
14
|
+
const [googlepay, setGooglePay] = useState(false);
|
|
15
|
+
const [braintreegatewayclient, setBraintreeGatewayClient] = useState(false);
|
|
16
|
+
const [braintreegatewaygooglepayment, setBraintreeGatewayGooglePayment] =
|
|
17
|
+
useState(false);
|
|
18
|
+
const [braintreegatewaydatacollector, setBraintreeGatewayDataCollector] =
|
|
19
|
+
useState(false);
|
|
20
|
+
|
|
21
|
+
let paymentsClient;
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (
|
|
25
|
+
!googlepayloaded &&
|
|
26
|
+
googlepay &&
|
|
27
|
+
braintreegatewaydatacollector &&
|
|
28
|
+
braintreegatewayclient &&
|
|
29
|
+
braintreegatewaygooglepayment
|
|
30
|
+
) {
|
|
31
|
+
console.log("okkkk");
|
|
32
|
+
onGooglePayLoaded();
|
|
33
|
+
}
|
|
34
|
+
}, [
|
|
35
|
+
googlepay,
|
|
36
|
+
braintreegatewayclient,
|
|
37
|
+
braintreegatewaygooglepayment,
|
|
38
|
+
braintreegatewaydatacollector,
|
|
39
|
+
googlepayloaded
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Add a Google Pay purchase button alongside an existing checkout button
|
|
44
|
+
*
|
|
45
|
+
* @see {@link https://developers.google.com/pay/api/web/reference/request-objects#ButtonOptions|Button options}
|
|
46
|
+
* @see {@link https://developers.google.com/pay/api/web/guides/brand-guidelines|Google Pay brand guidelines}
|
|
47
|
+
*/
|
|
48
|
+
const addGooglePayButton = (googlePaymentInstance, clientInstance) => {
|
|
49
|
+
//ok
|
|
50
|
+
const button = paymentsClient.createButton({
|
|
51
|
+
onClick: (event) =>
|
|
52
|
+
onGooglePaymentButtonClicked(
|
|
53
|
+
event,
|
|
54
|
+
googlePaymentInstance,
|
|
55
|
+
clientInstance
|
|
56
|
+
),
|
|
57
|
+
buttonLocale: lang
|
|
58
|
+
});
|
|
59
|
+
document.getElementById("qawaim-googlepay").appendChild(button);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Show Google Pay payment sheet when Google Pay payment button is clicked
|
|
64
|
+
*/
|
|
65
|
+
const onGooglePaymentButtonClicked = (
|
|
66
|
+
event,
|
|
67
|
+
googlePaymentInstance,
|
|
68
|
+
clientInstance
|
|
69
|
+
) => {
|
|
70
|
+
let paymentDataRequest = googlePaymentInstance.createPaymentDataRequest({
|
|
71
|
+
merchantInfo: {
|
|
72
|
+
// @todo a merchant ID is available for a production environment after approval by Google
|
|
73
|
+
// See {@link https://developers.google.com/pay/api/web/guides/test-and-deploy/integration-checklist|Integration checklist}
|
|
74
|
+
merchantId: `${process.env.NEXT_PUBLIC_QAWAIM_GOOGLE_MERCHANT_ID}`,
|
|
75
|
+
merchantName: `${process.env.NEXT_PUBLIC_QAWAIM_GOOGLEPAY_MERCHANT_NAME}`
|
|
76
|
+
},
|
|
77
|
+
transactionInfo: {
|
|
78
|
+
displayItems: [
|
|
79
|
+
{
|
|
80
|
+
label: "Subtotal",
|
|
81
|
+
type: "SUBTOTAL",
|
|
82
|
+
price: `${transaction.amount}`
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
currencyCode: `${transaction.currency}`,
|
|
86
|
+
totalPriceStatus: "FINAL",
|
|
87
|
+
totalPrice: `${transaction.amount}`,
|
|
88
|
+
totalPriceLabel: "Total"
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// We recommend collecting billing address information, at minimum
|
|
93
|
+
// billing postal code, and passing that billing postal code with all
|
|
94
|
+
// Google Pay card transactions as a best practice.
|
|
95
|
+
// See all available options at https://developers.google.com/pay/api/web/reference/object
|
|
96
|
+
let cardPaymentMethod = paymentDataRequest.allowedPaymentMethods[0];
|
|
97
|
+
cardPaymentMethod.parameters.billingAddressRequired = true;
|
|
98
|
+
cardPaymentMethod.parameters.billingAddressParameters = {
|
|
99
|
+
format: "FULL",
|
|
100
|
+
phoneNumberRequired: true
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
paymentsClient
|
|
104
|
+
.loadPaymentData(paymentDataRequest)
|
|
105
|
+
.then(function (paymentData) {
|
|
106
|
+
googlePaymentInstance.parseResponse(
|
|
107
|
+
paymentData,
|
|
108
|
+
function (err, result) {
|
|
109
|
+
if (err) {
|
|
110
|
+
console.log(err);
|
|
111
|
+
// Handle parsing error
|
|
112
|
+
router.push("/payment/error");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Send result.nonce to your server
|
|
116
|
+
// result.type may be either "AndroidPayCard" or "PayPalAccount", and
|
|
117
|
+
// paymentData will contain the billingAddress for card payments
|
|
118
|
+
braintree.dataCollector.create(
|
|
119
|
+
{
|
|
120
|
+
client: clientInstance
|
|
121
|
+
},
|
|
122
|
+
async function (err, dataCollectorInstance) {
|
|
123
|
+
if (err) {
|
|
124
|
+
// Handle error in creation of data collector
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
// At this point, you should access the dataCollectorInstance.deviceData value and provide it
|
|
128
|
+
// to your server, e.g. by injecting it into your form as a hidden input.
|
|
129
|
+
let deviceData = dataCollectorInstance.deviceData;
|
|
130
|
+
const data = {
|
|
131
|
+
deviceDataClient: deviceData,
|
|
132
|
+
nonce: result.nonce,
|
|
133
|
+
billing_address: transaction.billing_address,
|
|
134
|
+
amount: `${transaction.amount}`,
|
|
135
|
+
currency: token.SelectedCurrency?.toUpperCase(),
|
|
136
|
+
transaction_id: `${transaction._id}`
|
|
137
|
+
};
|
|
138
|
+
let checkoutgpay = await axios.post(
|
|
139
|
+
`${process.env.NEXT_PUBLIC_QAWAIM_API_URL}/braintreegateway/googlepay`,
|
|
140
|
+
qs.stringify(data)
|
|
141
|
+
);
|
|
142
|
+
if (checkoutgpay.data.ok === true) {
|
|
143
|
+
router.push(`/confirmation/${transaction._id}`);
|
|
144
|
+
//setCurrentTransaction(checkoutInfo.data.data.transaction);
|
|
145
|
+
router.push(
|
|
146
|
+
`/confirmation/${checkoutgpay.data.data.transaction._id}`
|
|
147
|
+
);
|
|
148
|
+
} else {
|
|
149
|
+
router.push("/payment/error");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
})
|
|
156
|
+
.catch(function (err) {
|
|
157
|
+
console.log(err);
|
|
158
|
+
router.push("/payment/error");
|
|
159
|
+
// Handle errors
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const onGooglePayLoaded = () => {
|
|
164
|
+
// Make sure to have https://pay.google.com/gp/p/js/pay.js loaded on your page
|
|
165
|
+
// You will need a button element on your page styled according to Google's brand guidelines
|
|
166
|
+
// https://developers.google.com/pay/api/web/guides/brand-guidelines
|
|
167
|
+
paymentsClient = new google.payments.api.PaymentsClient({
|
|
168
|
+
environment: process.env.NEXT_PUBLIC_QAWAIM_GOOGLEPAY_ENVIRONMENT // 'TEST' Or 'PRODUCTION'
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
setGooglePayLoaded(true);
|
|
172
|
+
|
|
173
|
+
braintree.client.create(
|
|
174
|
+
{
|
|
175
|
+
authorization: `${process.env.NEXT_PUBLIC_QAWAIM_BRAINTREE_TOKENIZATION_KEY}`
|
|
176
|
+
},
|
|
177
|
+
function (clientErr, clientInstance) {
|
|
178
|
+
console.log("clientErr=", clientErr);
|
|
179
|
+
console.log("clientInstance=", clientInstance);
|
|
180
|
+
braintree.googlePayment.create(
|
|
181
|
+
{
|
|
182
|
+
client: clientInstance,
|
|
183
|
+
googlePayVersion: 2,
|
|
184
|
+
googleMerchantId: `${process.env.NEXT_PUBLIC_QAWAIM_GOOGLE_MERCHANT_ID}` // Optional in sandbox; if set in sandbox, this value must be a valid production Google Merchant ID
|
|
185
|
+
},
|
|
186
|
+
function (googlePaymentErr, googlePaymentInstance) {
|
|
187
|
+
console.log("googlePaymentErr=", googlePaymentErr);
|
|
188
|
+
console.log("googlePaymentInstance=", googlePaymentInstance);
|
|
189
|
+
paymentsClient
|
|
190
|
+
.isReadyToPay({
|
|
191
|
+
// see https://developers.google.com/pay/api/web/reference/object#IsReadyToPayRequest
|
|
192
|
+
apiVersion: 2,
|
|
193
|
+
apiVersionMinor: 0,
|
|
194
|
+
allowedPaymentMethods:
|
|
195
|
+
googlePaymentInstance.createPaymentDataRequest()
|
|
196
|
+
.allowedPaymentMethods,
|
|
197
|
+
existingPaymentMethodRequired: true // Optional
|
|
198
|
+
})
|
|
199
|
+
.then(function (response) {
|
|
200
|
+
if (response.result) {
|
|
201
|
+
addGooglePayButton(googlePaymentInstance, clientInstance);
|
|
202
|
+
}
|
|
203
|
+
})
|
|
204
|
+
.catch(function (err) {
|
|
205
|
+
console.log(err);
|
|
206
|
+
router.push("/payment/error");
|
|
207
|
+
// Handle errors
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
// Set up other Braintree components
|
|
213
|
+
}
|
|
214
|
+
);
|
|
215
|
+
};
|
|
216
|
+
return (
|
|
217
|
+
<>
|
|
218
|
+
<Script
|
|
219
|
+
id="googlepay"
|
|
220
|
+
src="https://pay.google.com/gp/p/js/pay.js"
|
|
221
|
+
onLoad={() => {
|
|
222
|
+
setGooglePay(true);
|
|
223
|
+
}}
|
|
224
|
+
/>
|
|
225
|
+
<Script
|
|
226
|
+
id="braintreegateway-client"
|
|
227
|
+
src="https://js.braintreegateway.com/web/3.82.0/js/client.min.js"
|
|
228
|
+
onLoad={() => {
|
|
229
|
+
setBraintreeGatewayClient(true);
|
|
230
|
+
}}
|
|
231
|
+
/>
|
|
232
|
+
<Script
|
|
233
|
+
id="braintreegateway-data-collector"
|
|
234
|
+
src="https://js.braintreegateway.com/web/3.82.0/js/data-collector.min.js"
|
|
235
|
+
onLoad={() => {
|
|
236
|
+
setBraintreeGatewayDataCollector(true);
|
|
237
|
+
}}
|
|
238
|
+
/>
|
|
239
|
+
<Script
|
|
240
|
+
id="braintreegateway-google-payment"
|
|
241
|
+
src="https://js.braintreegateway.com/web/3.82.0/js/google-payment.min.js"
|
|
242
|
+
onLoad={() => {
|
|
243
|
+
setBraintreeGatewayGooglePayment(true);
|
|
244
|
+
}}
|
|
245
|
+
/>
|
|
246
|
+
<div id="qawaim-googlepay"></div>
|
|
247
|
+
</>
|
|
248
|
+
);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
export default GooglePay;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { useState, useEffect, memo, useCallback, useRef } from "react";
|
|
2
|
+
import CForm from "../Form/CForm";
|
|
3
|
+
import Card from "../Form/Card";
|
|
4
|
+
|
|
5
|
+
const initialState = {
|
|
6
|
+
cardNumber: "#### #### #### ####",
|
|
7
|
+
cardHolder: "FULL NAME",
|
|
8
|
+
cardMonth: "",
|
|
9
|
+
cardYear: "",
|
|
10
|
+
cardCvv: "",
|
|
11
|
+
isCardFlipped: false
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const Payfort = (props) => {
|
|
15
|
+
const [state, setState] = useState(initialState);
|
|
16
|
+
const [currentFocusedElm, setCurrentFocusedElm] = useState(null);
|
|
17
|
+
|
|
18
|
+
const updateStateValues = useCallback(
|
|
19
|
+
(keyName, value) => {
|
|
20
|
+
setState({
|
|
21
|
+
...state,
|
|
22
|
+
[keyName]: value || initialState[keyName]
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
[state]
|
|
26
|
+
);
|
|
27
|
+
// References for the Form Inputs used to focus corresponding inputs.
|
|
28
|
+
let formFieldsRefObj = {
|
|
29
|
+
cardNumber: useRef(),
|
|
30
|
+
cardHolder: useRef(),
|
|
31
|
+
cardDate: useRef(),
|
|
32
|
+
cardCvv: useRef()
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
let focusFormFieldByKey = useCallback((key) => {
|
|
36
|
+
formFieldsRefObj[key].current.focus();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// This are the references for the Card DIV elements.
|
|
40
|
+
let cardElementsRef = {
|
|
41
|
+
cardNumber: useRef(),
|
|
42
|
+
cardHolder: useRef(),
|
|
43
|
+
cardDate: useRef()
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
let onCardFormInputFocus = (_event, inputName) => {
|
|
47
|
+
const refByName = cardElementsRef[inputName];
|
|
48
|
+
setCurrentFocusedElm(refByName);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
let onCardInputBlur = useCallback(() => {
|
|
52
|
+
setCurrentFocusedElm(null);
|
|
53
|
+
}, []);
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<CForm
|
|
57
|
+
cardNumber={state.cardNumber}
|
|
58
|
+
cardHolder={state.cardHolder}
|
|
59
|
+
cardMonth={state.cardMonth}
|
|
60
|
+
cardYear={state.cardYear}
|
|
61
|
+
cardCvv={state.cardCvv}
|
|
62
|
+
onUpdateState={updateStateValues}
|
|
63
|
+
cardNumberRef={formFieldsRefObj.cardNumber}
|
|
64
|
+
cardHolderRef={formFieldsRefObj.cardHolder}
|
|
65
|
+
cardDateRef={formFieldsRefObj.cardDate}
|
|
66
|
+
cardCvvRef={formFieldsRefObj.cardCvv}
|
|
67
|
+
onCardInputFocus={onCardFormInputFocus}
|
|
68
|
+
onCardInputBlur={onCardInputBlur}
|
|
69
|
+
handlePaymentPayfort={props.handlePaymentPayfort}
|
|
70
|
+
paymentMethod={props.paymentMethod}
|
|
71
|
+
register={props.register}
|
|
72
|
+
>
|
|
73
|
+
<Card
|
|
74
|
+
cardNumber={state.cardNumber}
|
|
75
|
+
cardHolder={state.cardHolder}
|
|
76
|
+
cardMonth={state.cardMonth}
|
|
77
|
+
cardYear={state.cardYear}
|
|
78
|
+
cardCvv={state.cardCvv}
|
|
79
|
+
isCardFlipped={state.isCardFlipped}
|
|
80
|
+
currentFocusedElm={currentFocusedElm}
|
|
81
|
+
onCardElementClick={focusFormFieldByKey}
|
|
82
|
+
cardNumberRef={cardElementsRef.cardNumber}
|
|
83
|
+
cardHolderRef={cardElementsRef.cardHolder}
|
|
84
|
+
cardDateRef={cardElementsRef.cardDate}
|
|
85
|
+
></Card>
|
|
86
|
+
</CForm>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export default Payfort;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import qs from "qs";
|
|
4
|
+
import {
|
|
5
|
+
PayPalButtons,
|
|
6
|
+
usePayPalScriptReducer,
|
|
7
|
+
PayPalScriptProvider
|
|
8
|
+
} from "@paypal/react-paypal-js";
|
|
9
|
+
|
|
10
|
+
// This values are the props in the UI
|
|
11
|
+
const currency = "USD";
|
|
12
|
+
const style = {
|
|
13
|
+
layout: "vertical",
|
|
14
|
+
color: "blue",
|
|
15
|
+
shape: "rect",
|
|
16
|
+
label: "paypal"
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const Paypal = (props) => {
|
|
20
|
+
return (
|
|
21
|
+
<PayPalScriptProvider
|
|
22
|
+
deferLoading={true}
|
|
23
|
+
options={{
|
|
24
|
+
"client-id": `${process.env.NEXT_PUBLIC_PAYPAL_CLIENT_ID}`,
|
|
25
|
+
locale: lang === "ar" ? "ar_SA" : "en_US"
|
|
26
|
+
}}
|
|
27
|
+
>
|
|
28
|
+
<ButtonWrapper
|
|
29
|
+
currency={currency}
|
|
30
|
+
showSpinner={false}
|
|
31
|
+
amount={getFinalPricePaypal(
|
|
32
|
+
invoice.currency?.toLowerCase() == "sar"
|
|
33
|
+
? invoice.invoice_discount
|
|
34
|
+
: invoice.invoice_discount_usd
|
|
35
|
+
)}
|
|
36
|
+
lang={lang}
|
|
37
|
+
invoiceObject={invoiceObject}
|
|
38
|
+
router={router}
|
|
39
|
+
/>
|
|
40
|
+
</PayPalScriptProvider>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Custom component to wrap the PayPalButtons and handle currency changes
|
|
45
|
+
const ButtonWrapper = ({
|
|
46
|
+
amount,
|
|
47
|
+
currency,
|
|
48
|
+
showSpinner,
|
|
49
|
+
lang,
|
|
50
|
+
invoiceObject,
|
|
51
|
+
router
|
|
52
|
+
}) => {
|
|
53
|
+
// usePayPalScriptReducer can be use only inside children of PayPalScriptProviders
|
|
54
|
+
// This is the main reason to wrap the PayPalButtons in a new component
|
|
55
|
+
const [{ options, isPending }, dispatch] = usePayPalScriptReducer();
|
|
56
|
+
console.log("amount=", amount);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
dispatch({
|
|
59
|
+
type: "resetOptions",
|
|
60
|
+
value: {
|
|
61
|
+
...options,
|
|
62
|
+
currency: currency
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}, [currency, showSpinner]);
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div
|
|
69
|
+
style={{
|
|
70
|
+
padding: "10px",
|
|
71
|
+
marginTop: "10px",
|
|
72
|
+
fontSize: "17px",
|
|
73
|
+
width: "100%"
|
|
74
|
+
}}
|
|
75
|
+
>
|
|
76
|
+
{showSpinner && isPending && <div className="spinner" />}
|
|
77
|
+
<PayPalButtons
|
|
78
|
+
style={style}
|
|
79
|
+
disabled={false}
|
|
80
|
+
//forceReRender={[amount, currency, style]}
|
|
81
|
+
fundingSource={undefined}
|
|
82
|
+
createOrder={(data, actions) => {
|
|
83
|
+
console.log("lang=", amount);
|
|
84
|
+
return actions.order
|
|
85
|
+
.create({
|
|
86
|
+
purchase_units: [
|
|
87
|
+
{
|
|
88
|
+
amount: {
|
|
89
|
+
currency_code: currency,
|
|
90
|
+
value: amount
|
|
91
|
+
},
|
|
92
|
+
reference_id: invoiceObject._id
|
|
93
|
+
/*items: [
|
|
94
|
+
name: ,
|
|
95
|
+
unit_amount: ,
|
|
96
|
+
tax: ,
|
|
97
|
+
quantity: ,
|
|
98
|
+
description: ,
|
|
99
|
+
]*/
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
application_context: {
|
|
103
|
+
locale: lang === "ar" ? "ar-SA" : "en-US"
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
.then((orderId) => {
|
|
107
|
+
// Your code here after create the order
|
|
108
|
+
return orderId;
|
|
109
|
+
});
|
|
110
|
+
}}
|
|
111
|
+
onApprove={async function (data, actions) {
|
|
112
|
+
return actions.order.capture().then(async function (details) {
|
|
113
|
+
console.log("data=", details);
|
|
114
|
+
details["language"] = lang;
|
|
115
|
+
let checkoutInfo = await axios.post(
|
|
116
|
+
`${process.env.NEXT_PUBLIC_SIKKA_API_URL}/paypal/payment/finalize`,
|
|
117
|
+
qs.stringify(details)
|
|
118
|
+
);
|
|
119
|
+
if (checkoutInfo.data?.ok === true) {
|
|
120
|
+
router.push({
|
|
121
|
+
pathname: "/confirmation/" + checkoutInfo.data.transaction._id
|
|
122
|
+
});
|
|
123
|
+
} else {
|
|
124
|
+
router.push({
|
|
125
|
+
pathname: "/payment/error/" + props.data.merchant_reference,
|
|
126
|
+
query: {
|
|
127
|
+
code: 74
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}}
|
|
133
|
+
/>
|
|
134
|
+
</div>
|
|
135
|
+
);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export default Paypal;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import useTranslation from "next-translate/useTranslation";
|
|
2
|
+
import Button from "@mui/material/Button";
|
|
3
|
+
import Grid from "@mui/material/Grid";
|
|
4
|
+
import Paper from "@mui/material/Paper";
|
|
5
|
+
import CircularProgress from "@mui/material/CircularProgress";
|
|
6
|
+
import { makeStyles } from "@mui/material/styles";
|
|
7
|
+
|
|
8
|
+
const useStyles = makeStyles((theme) => ({
|
|
9
|
+
root: {
|
|
10
|
+
flexGrow: 1
|
|
11
|
+
},
|
|
12
|
+
paper: {
|
|
13
|
+
padding: theme.spacing(2),
|
|
14
|
+
textAlign: "center",
|
|
15
|
+
color: theme.palette.text.secondary
|
|
16
|
+
}
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
const Wallet = (props) => {
|
|
20
|
+
const { t } = useTranslation("common");
|
|
21
|
+
const classes = useStyles();
|
|
22
|
+
return (
|
|
23
|
+
<div className="block-pay-content" style={{ padding: 20 }}>
|
|
24
|
+
<div key="Payment">
|
|
25
|
+
<>
|
|
26
|
+
<Grid
|
|
27
|
+
container
|
|
28
|
+
spacing={3}
|
|
29
|
+
alignContent={"center"}
|
|
30
|
+
alignItems={"center"}
|
|
31
|
+
style={{ width: "100%", margin: 0 }}
|
|
32
|
+
>
|
|
33
|
+
<Grid item xs={4}>
|
|
34
|
+
<Paper
|
|
35
|
+
className={classes.paper}
|
|
36
|
+
style={{
|
|
37
|
+
boxShadow: "none",
|
|
38
|
+
fontWeight: "bold"
|
|
39
|
+
}}
|
|
40
|
+
>
|
|
41
|
+
{t("payment-made")} <br />
|
|
42
|
+
{props.amount} {t(props.SelectedCurrency)}
|
|
43
|
+
</Paper>
|
|
44
|
+
</Grid>
|
|
45
|
+
<Grid
|
|
46
|
+
item
|
|
47
|
+
style={{
|
|
48
|
+
padding: 0,
|
|
49
|
+
margin: "-5px"
|
|
50
|
+
}}
|
|
51
|
+
>
|
|
52
|
+
<Paper
|
|
53
|
+
className={classes.paper}
|
|
54
|
+
style={{
|
|
55
|
+
backgroundColor: "transparent",
|
|
56
|
+
boxShadow: "none",
|
|
57
|
+
fontSize: "18px",
|
|
58
|
+
fontWeight: "bold",
|
|
59
|
+
padding: 0
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
-
|
|
63
|
+
</Paper>
|
|
64
|
+
</Grid>
|
|
65
|
+
<Grid item xs={4}>
|
|
66
|
+
<Paper
|
|
67
|
+
className={classes.paper}
|
|
68
|
+
style={{
|
|
69
|
+
boxShadow: "none",
|
|
70
|
+
fontWeight: "bold"
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
{t("amount-in-wallet")} <br />
|
|
74
|
+
{props.total_wallet.toFixed(2)} {t(props.SelectedCurrency)}
|
|
75
|
+
</Paper>
|
|
76
|
+
</Grid>
|
|
77
|
+
<Grid
|
|
78
|
+
item
|
|
79
|
+
style={{
|
|
80
|
+
padding: 0,
|
|
81
|
+
margin: "-5px"
|
|
82
|
+
}}
|
|
83
|
+
>
|
|
84
|
+
<Paper
|
|
85
|
+
className={classes.paper}
|
|
86
|
+
style={{
|
|
87
|
+
backgroundColor: "transparent",
|
|
88
|
+
boxShadow: "none",
|
|
89
|
+
fontSize: "18px",
|
|
90
|
+
fontWeight: "bold",
|
|
91
|
+
padding: 0
|
|
92
|
+
}}
|
|
93
|
+
>
|
|
94
|
+
=
|
|
95
|
+
</Paper>
|
|
96
|
+
</Grid>
|
|
97
|
+
<Grid item xs={4}>
|
|
98
|
+
<Paper
|
|
99
|
+
className={classes.paper}
|
|
100
|
+
style={{
|
|
101
|
+
boxShadow: "none",
|
|
102
|
+
fontWeight: "bold"
|
|
103
|
+
}}
|
|
104
|
+
>
|
|
105
|
+
{t("left-amount-wallet")} <br />
|
|
106
|
+
{props.leftAmount.toFixed(2)} {t(props.SelectedCurrency)}
|
|
107
|
+
</Paper>
|
|
108
|
+
</Grid>
|
|
109
|
+
<Grid item xs={12}>
|
|
110
|
+
<Paper
|
|
111
|
+
className={classes.paper}
|
|
112
|
+
style={{
|
|
113
|
+
boxShadow: "none",
|
|
114
|
+
fontWeight: "bold"
|
|
115
|
+
}}
|
|
116
|
+
>
|
|
117
|
+
{t("remaining-amount")}: {props.remainingAmount.toFixed(2)}{" "}
|
|
118
|
+
{t(props.SelectedCurrency)}
|
|
119
|
+
</Paper>
|
|
120
|
+
</Grid>
|
|
121
|
+
{!props.leftAmount && (
|
|
122
|
+
<Grid item xs={12}>
|
|
123
|
+
<Button
|
|
124
|
+
variant="contained"
|
|
125
|
+
color="primary"
|
|
126
|
+
fullWidth
|
|
127
|
+
type="submit"
|
|
128
|
+
onClick={(e) => props.handleWalletPayNow(e)}
|
|
129
|
+
>
|
|
130
|
+
{props.loading ? (
|
|
131
|
+
<CircularProgress
|
|
132
|
+
variant="indeterminate"
|
|
133
|
+
style={{ color: "white" }}
|
|
134
|
+
size={25}
|
|
135
|
+
/>
|
|
136
|
+
) : (
|
|
137
|
+
t("pay-now")
|
|
138
|
+
)}
|
|
139
|
+
</Button>
|
|
140
|
+
</Grid>
|
|
141
|
+
)}
|
|
142
|
+
</Grid>
|
|
143
|
+
</>
|
|
144
|
+
</div>
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export default Wallet;
|