@sikka/hawa 0.0.3 → 0.0.4
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 +2 -0
- package/es/index.es.js +1 -0
- package/lib/index.js +1 -0
- package/package.json +18 -8
- package/rollup.config.js +2 -2
- 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/Payment/Form/CForm.js +326 -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/index.js +13 -0
- package/src/index.js +2 -1
- package/src/styles.scss +679 -0
- package/tools/build-styles.js +17 -0
|
@@ -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 "@material-ui/core/Button";
|
|
3
|
+
import Grid from "@material-ui/core/Grid";
|
|
4
|
+
import Paper from "@material-ui/core/Paper";
|
|
5
|
+
import CircularProgress from "@material-ui/core/CircularProgress";
|
|
6
|
+
import { makeStyles } from "@material-ui/core/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;
|