moyasar-payment-form 2.0.3
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/LICENCE.md +7 -0
- package/README.md +695 -0
- package/dist/__vite-browser-external-DYxpcVy9.mjs +11 -0
- package/dist/moyasar.css +8 -0
- package/dist/moyasar.d.ts +6 -0
- package/dist/moyasar.mjs +3281 -0
- package/dist/moyasar.umd.js +10 -0
- package/package.json +61 -0
package/LICENCE.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2020 Moyasar Ltd.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,695 @@
|
|
|
1
|
+
# Moyasar Payment Form
|
|
2
|
+
|
|
3
|
+
# Usage
|
|
4
|
+
|
|
5
|
+
Sample Usage:
|
|
6
|
+
|
|
7
|
+
```html
|
|
8
|
+
<!-- We must provide an empty element that moyasar form will be mounted into -->
|
|
9
|
+
<div class="mysr-form"></div>
|
|
10
|
+
|
|
11
|
+
<script>
|
|
12
|
+
Moyasar.init({
|
|
13
|
+
// Root must be an Element or a string with a valid CSS selector to an element
|
|
14
|
+
element: '.mysr-form',
|
|
15
|
+
|
|
16
|
+
// Set the form language
|
|
17
|
+
// Default: <taken from current page>, falls back to en
|
|
18
|
+
language: 'ar',
|
|
19
|
+
|
|
20
|
+
// Provide additional translations
|
|
21
|
+
// Default: en and ar
|
|
22
|
+
translations: [
|
|
23
|
+
'de': {
|
|
24
|
+
// This is just a sample
|
|
25
|
+
// Checkout resources/lang/en.json for the full list
|
|
26
|
+
'error.authentication_error': 'Authentifizierungsfehler, Dienst ist jetzt nicht verfügbar'
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
|
|
30
|
+
// Set predefined option to ApplePay and card pay buttons, defaults to pay
|
|
31
|
+
payment_button_type: 'buy'
|
|
32
|
+
|
|
33
|
+
// Amount to pay in smallest currency unit (minor)
|
|
34
|
+
amount: 100,
|
|
35
|
+
|
|
36
|
+
// Currency
|
|
37
|
+
currency: 'SAR',
|
|
38
|
+
|
|
39
|
+
// Country (Needed for Apple Pay to function)
|
|
40
|
+
country: 'SA',
|
|
41
|
+
|
|
42
|
+
// Description of the payment
|
|
43
|
+
description: 'Testing Moyasar payment form',
|
|
44
|
+
|
|
45
|
+
// Publishable API key
|
|
46
|
+
publishable_api_key: 'pk_live_some-random-string',
|
|
47
|
+
|
|
48
|
+
// Supported networks (Used to display icons in payment form, and to accept only supported networks in Apple Pay)
|
|
49
|
+
// default: ['mada', 'visa', 'mastercard']
|
|
50
|
+
supported_networks: [
|
|
51
|
+
'mada',
|
|
52
|
+
'visa',
|
|
53
|
+
'mastercard',
|
|
54
|
+
'amex',
|
|
55
|
+
],
|
|
56
|
+
|
|
57
|
+
// Form payment methods, default: ['creditcard', 'applepay', 'stcpay']
|
|
58
|
+
payment_methods: [
|
|
59
|
+
'creditcard',
|
|
60
|
+
'applepay',
|
|
61
|
+
'stcpay'
|
|
62
|
+
],
|
|
63
|
+
|
|
64
|
+
// Optional: Used for doing any job before payment is submitted, can also cancel payment
|
|
65
|
+
before_payment_callback: function (proceed, abort) {
|
|
66
|
+
if (1 > 2) {
|
|
67
|
+
proceed();
|
|
68
|
+
} else {
|
|
69
|
+
abort();
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
// When a payment is initiated, the library will use this handler
|
|
74
|
+
// Types:
|
|
75
|
+
// 1 - string, a URL that will recieve the payment object (HTTP method: POST)
|
|
76
|
+
// 2 - function, will be called with the payment object as an argument
|
|
77
|
+
on_payment_init: '/checkout/payments/initiated',
|
|
78
|
+
|
|
79
|
+
// When a payment is completed (either failed or succeeded), the library will use this handler
|
|
80
|
+
// Types:
|
|
81
|
+
// 1 - string, a URL that will recieve the payment object (HTTP method: POST)
|
|
82
|
+
// 2 - function, will be called with the payment object as an argument
|
|
83
|
+
on_payment_complete: '/checkout/payments/completed',
|
|
84
|
+
|
|
85
|
+
// Moyasar's form callback URL, will be used to redirect the user when the payment has finished (Required)
|
|
86
|
+
callback_url: 'https://my-store.xyz/checkout/payments/redirect',
|
|
87
|
+
|
|
88
|
+
// Optional: can be used to control the redirection behaviour
|
|
89
|
+
on_redirect: function (url) {
|
|
90
|
+
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
// Apple Pay Configurations (Required when ApplePay is enabled)
|
|
94
|
+
apple_pay: {
|
|
95
|
+
// Payment label
|
|
96
|
+
label: 'My Store XYZ',
|
|
97
|
+
|
|
98
|
+
// This endpoint must be implemented on the users backend
|
|
99
|
+
// A JSON object will be posted to the URL (HTTP method: POST)
|
|
100
|
+
// JSON: {validation_url: 'https://example.apple.com/validation/url'}
|
|
101
|
+
// The server must use the given URL and make a POST request to it using
|
|
102
|
+
// the merchant validation certificate (In SSL options)
|
|
103
|
+
// The returned JSON object from Apple must be returned to the browser as is
|
|
104
|
+
// with "Content-Type: application/json" header set in order for the library
|
|
105
|
+
// to parse it
|
|
106
|
+
validate_merchant_url: '/checkout/payments/apple-pay/validate-merchant',
|
|
107
|
+
|
|
108
|
+
// Optional: Used to provide merchant capabilities for moyasar
|
|
109
|
+
merchant_capabilities: [
|
|
110
|
+
|
|
111
|
+
],
|
|
112
|
+
|
|
113
|
+
// Optional: Used to control Apple Pay JS version
|
|
114
|
+
// Default: 6
|
|
115
|
+
version: 9,
|
|
116
|
+
|
|
117
|
+
// Optional: Used to handle authorization of payment
|
|
118
|
+
// Args: payment object is passed from Apple to handler
|
|
119
|
+
on_authorize: function (paymentObject) {
|
|
120
|
+
// Manually handle auth (send it to Moyasar)
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
// Optional, (used for development purposes only, please don't use it)
|
|
125
|
+
base_url: 'https://api.moyasar.com',
|
|
126
|
+
|
|
127
|
+
// Optional: Used to handle failures of the form
|
|
128
|
+
on_failure: function (error) {
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
</script>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Configuration
|
|
136
|
+
|
|
137
|
+
Here is a list of acceptable configurations values for the form.
|
|
138
|
+
|
|
139
|
+
### Element (element) [Required]
|
|
140
|
+
|
|
141
|
+
Element must be a valid CSS selector for the target element for form to be mounted in. Or
|
|
142
|
+
can be an instance of DOM element `Element`. Here is an example:
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
element: '.payment-form', // Using a class
|
|
146
|
+
element: '#payment-form', // Using an ID
|
|
147
|
+
element: document.querySelector('.payment-form'), // or just providing an Element instance
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Language (language) [Optional]
|
|
151
|
+
|
|
152
|
+
This option can be used to set display language for the form. If left empty,
|
|
153
|
+
language will be inferred from `<html>` element then fallback to `en` if it cannot
|
|
154
|
+
be inferred. Here is an example
|
|
155
|
+
|
|
156
|
+
```javascript
|
|
157
|
+
language: 'en', // Displaying the form in English
|
|
158
|
+
language: 'ar', // Displaying the form in Arabic
|
|
159
|
+
language: 'fr', // Displaying the form in French (You need to provide your own translations)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Translations (translations) [Optional]
|
|
163
|
+
|
|
164
|
+
This option is used to add more translations to the form. Here is an example:
|
|
165
|
+
|
|
166
|
+
```javascript
|
|
167
|
+
translations: {
|
|
168
|
+
fr: {
|
|
169
|
+
"validation.should_be_english_letters_only": "Le nom ne peut avoir que l'alphabet anglais et des espaces",
|
|
170
|
+
"validation.first_and_last_name_required": "Le prénom et le nom de famille sont obligatoires",
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Payment Button Type (payment_button_type) [Optional]
|
|
176
|
+
|
|
177
|
+
This options allow to set predefined text for pay buttons - in card from and ApplePay (if configured).
|
|
178
|
+
|
|
179
|
+
```javascript
|
|
180
|
+
payment_button_type: 'plain'; // Will display no additional text, only amount
|
|
181
|
+
payment_button_type: 'pay'; // Will display "Pay" label
|
|
182
|
+
payment_button_type: 'buy'; // Will display "Buy with" label
|
|
183
|
+
payment_button_type: 'donate'; // Will display "Donate with" label
|
|
184
|
+
payment_button_type: 'book'; // Will display "Book with" label
|
|
185
|
+
payment_button_type: 'check-out'; // Will display "Check out with" label
|
|
186
|
+
payment_button_type: 'subscribe'; // Will display "Subscribe with" label
|
|
187
|
+
payment_button_type: 'add-money'; // Will display "Add money with" label
|
|
188
|
+
payment_button_type: 'contribute'; // Will display "Contribute with" label
|
|
189
|
+
payment_button_type: 'order'; // Will display "Order with" label
|
|
190
|
+
payment_button_type: 'reload'; // Will display "Reload with" label
|
|
191
|
+
payment_button_type: 'rent'; // Will display "Rent with" label
|
|
192
|
+
payment_button_type: 'support'; // Will display "Support with" label
|
|
193
|
+
payment_button_type: 'tip'; // Will display "Tip with" label
|
|
194
|
+
payment_button_type: 'top-up'; // Will display "Top Up with" label
|
|
195
|
+
payment_button_type: 'continue'; // Will display "Continue with payment" label
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Publishable API Key (publishable_api_key) [Required]
|
|
199
|
+
|
|
200
|
+
The publishable API key is required in order to communicate with Moyasar's API
|
|
201
|
+
and complete the payment request. Here is an example:
|
|
202
|
+
|
|
203
|
+
You can get both keys from your account at [Moyasar Dashboard](https://dashboard.moyasar.com)
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
// Live key is used in production environemnt and will require a valid SSL certificate
|
|
207
|
+
publishable_api_key: 'pk_live_AQpxBV3a29qm392e4mkasjnRhzADVrxSq5ydVNui',
|
|
208
|
+
|
|
209
|
+
// This will put the form in testing mode and allow you to test without an SSL certificate
|
|
210
|
+
publishable_api_key: 'pk_test_AQpxBV3a29qm392e4mrT4Fawd3ADVrxSq5ydVNui',
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Payment Methods (methods) [Optional]
|
|
214
|
+
|
|
215
|
+
This is used to enable and disable payment methods on the form.
|
|
216
|
+
By default, all the methods are enabled, which are:
|
|
217
|
+
|
|
218
|
+
- Credit Card (creditcard)
|
|
219
|
+
- Apple Pay (applepay)
|
|
220
|
+
- Stc Pay (stcpay)
|
|
221
|
+
|
|
222
|
+
```javascript
|
|
223
|
+
// Enabling only Credit Card and Apple Pay
|
|
224
|
+
methods: ['creditcard', 'applepay'];
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Amount (amount) [Required]
|
|
228
|
+
|
|
229
|
+
This sets the amount for user to pay.
|
|
230
|
+
Amount must be in minor unit of selected currency, e.g. if we want to
|
|
231
|
+
get a payment of $10 then we must represent the amount in Cents 1000.
|
|
232
|
+
Here is an example:
|
|
233
|
+
|
|
234
|
+
```javascript
|
|
235
|
+
amount: 1000;
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Currency (currency) [Required]
|
|
239
|
+
|
|
240
|
+
This sets which currency is used for the amount to be paid.
|
|
241
|
+
Here is an example:
|
|
242
|
+
|
|
243
|
+
```javascript
|
|
244
|
+
currency: 'USD', // Get payment in US Dollars
|
|
245
|
+
currency: 'SAR', // Get payment in Saudi Riyals
|
|
246
|
+
currency: 'JPY', // Get Payment in Japanese Yen
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
The currency must be in ISO 3166-1 alpha-3 country code format.
|
|
250
|
+
|
|
251
|
+
### Description (description) [Required]
|
|
252
|
+
|
|
253
|
+
This option is used to set a description to be sent along other payment information
|
|
254
|
+
to Moyasar's API. Here is an example:
|
|
255
|
+
|
|
256
|
+
```javascript
|
|
257
|
+
description: 'Payment for Order #34321';
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
The description can be any string you want.
|
|
261
|
+
|
|
262
|
+
### Callback URL (callback_url) [Required]
|
|
263
|
+
|
|
264
|
+
This URL is used by Moyasar to redirect the user back after the payment is either
|
|
265
|
+
successful, or the user has completed 3D stage.
|
|
266
|
+
|
|
267
|
+
### Supported Networks (supported_networks) [Optional]
|
|
268
|
+
|
|
269
|
+
This optional configuration option is used to set accepted card networks
|
|
270
|
+
in the form. The default value is all networks except `amex`.
|
|
271
|
+
|
|
272
|
+
Supported Networks:
|
|
273
|
+
|
|
274
|
+
- Mada (mada)
|
|
275
|
+
- Visa (visa)
|
|
276
|
+
- Mastercard (mastercard)
|
|
277
|
+
- American Express (amex)
|
|
278
|
+
|
|
279
|
+
Example:
|
|
280
|
+
|
|
281
|
+
```javascript
|
|
282
|
+
supported_networks: [
|
|
283
|
+
'mada',
|
|
284
|
+
'visa',
|
|
285
|
+
'mastercard',
|
|
286
|
+
'amex'
|
|
287
|
+
],
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### Fixed Width (fixed_width) [Optional]
|
|
291
|
+
|
|
292
|
+
This option is used to limit the form width to only `360px` and it is
|
|
293
|
+
enabled by default. To disable this just set it to `false`.
|
|
294
|
+
|
|
295
|
+
Example:
|
|
296
|
+
|
|
297
|
+
```javascript
|
|
298
|
+
fixed_width: false,
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### On Initiating (on_initiating) [Optional]
|
|
302
|
+
|
|
303
|
+
This `Promise` based callback is used to handle the event when a user starts a payment method
|
|
304
|
+
and before any information is sent to Moyasar's API. You can use this to perform
|
|
305
|
+
any last second validations or to prepare something.
|
|
306
|
+
|
|
307
|
+
When you handle this event, you can return a `false` to stop the payment process,
|
|
308
|
+
or a dictionary that is either empty or contains `description` or `callback_url`
|
|
309
|
+
values to update the form configurations if you need to.
|
|
310
|
+
|
|
311
|
+
Here is an example to stop the form from submitting:
|
|
312
|
+
|
|
313
|
+
```javascript
|
|
314
|
+
on_initiating: async () => {
|
|
315
|
+
return false;
|
|
316
|
+
};
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Make the form proceed:
|
|
320
|
+
|
|
321
|
+
```javascript
|
|
322
|
+
on_initiating: async function () {
|
|
323
|
+
return {};
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### On Completed (on_completed) [Optional]
|
|
328
|
+
|
|
329
|
+
This event is fired when a payment is created by Moyasar's API. You can,
|
|
330
|
+
intercept the payment to save it or do any other processing, by providing a `Promise` based callback;
|
|
331
|
+
|
|
332
|
+
Example:
|
|
333
|
+
|
|
334
|
+
```javascript
|
|
335
|
+
on_completed: async function (payment) {
|
|
336
|
+
// savePayment is just an example, your usage may vary.
|
|
337
|
+
savePayment(payment)
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### On Failure (on_failure) [Optional]
|
|
342
|
+
|
|
343
|
+
This event is used to handle payment failure, you will get a `string`
|
|
344
|
+
if there is an error.
|
|
345
|
+
|
|
346
|
+
Example:
|
|
347
|
+
|
|
348
|
+
```javascript
|
|
349
|
+
on_failure: async (error) =>
|
|
350
|
+
new Promise((resolve, reject) => {
|
|
351
|
+
// Handle error
|
|
352
|
+
resolve();
|
|
353
|
+
});
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### On Redirect (on_redirect) [Optional]
|
|
357
|
+
|
|
358
|
+
When the form finishes it work and is about to redirect the user, you can
|
|
359
|
+
intercept this action and handle redirection manually. Here is an example:
|
|
360
|
+
|
|
361
|
+
```javascript
|
|
362
|
+
on_redirect: async (url) =>
|
|
363
|
+
new Promise((resolve, reject) => {
|
|
364
|
+
// Handle redirection manually
|
|
365
|
+
resolve();
|
|
366
|
+
});
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
## Credit Card Configuration Options (credit_card)
|
|
370
|
+
|
|
371
|
+
This section describes Credit Card related options.
|
|
372
|
+
|
|
373
|
+
### Manual (manual)
|
|
374
|
+
|
|
375
|
+
This option allows you to only authorize the payment without capturing it. You will need to capture the payment later
|
|
376
|
+
using Moyasar API. Make a post `POST` to `/v1/payments/{id}/capture`.
|
|
377
|
+
|
|
378
|
+
Note: you need to enable this feature before using it.
|
|
379
|
+
|
|
380
|
+
```javascript
|
|
381
|
+
credit_card: {
|
|
382
|
+
manual: true;
|
|
383
|
+
}
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
### Save Card (save_card)
|
|
387
|
+
|
|
388
|
+
This option allows you to tokenize the card while completing the transaction.
|
|
389
|
+
|
|
390
|
+
Note: you need to enable this feature before using it.
|
|
391
|
+
|
|
392
|
+
```javascript
|
|
393
|
+
credit_card: {
|
|
394
|
+
save_card: true;
|
|
395
|
+
}
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
## Apple Pay Configurations (apple_pay) [Required if Apple Pay is activated]
|
|
399
|
+
|
|
400
|
+
This is an object that contains Apple Pay specific configurations. Here is
|
|
401
|
+
an example:
|
|
402
|
+
|
|
403
|
+
```javascript
|
|
404
|
+
apple_pay: {
|
|
405
|
+
// Apple Pay Configurations
|
|
406
|
+
}
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Version (version) [Optional]
|
|
410
|
+
|
|
411
|
+
This is used to specify Apple Pay JS version. Default is `6`. Here is an example:
|
|
412
|
+
|
|
413
|
+
```javascript
|
|
414
|
+
apple_pay: {
|
|
415
|
+
version: 7;
|
|
416
|
+
}
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
### Country (country) [Required]
|
|
420
|
+
|
|
421
|
+
Apple Pay merchant country. If other payment methods (Samsung Pay and/or Google Pay) are active, this can be set in `payment_options.country` to unify settings between multiple payments.
|
|
422
|
+
|
|
423
|
+
```javascript
|
|
424
|
+
apple_pay: {
|
|
425
|
+
country: 'SA';
|
|
426
|
+
}
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
or
|
|
430
|
+
|
|
431
|
+
```javascript
|
|
432
|
+
payment_options: {
|
|
433
|
+
country: 'SA';
|
|
434
|
+
}
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
### Merchant Capabilities (merchant_capabilities) [Optional]
|
|
438
|
+
|
|
439
|
+
Merchant capabilities to activate for this Apple Pay session. Default is:
|
|
440
|
+
|
|
441
|
+
```javascript
|
|
442
|
+
apple_pay: {
|
|
443
|
+
merchant_capabilities: [
|
|
444
|
+
'supports3DS',
|
|
445
|
+
'supportsCredit',
|
|
446
|
+
'supportsDebit'
|
|
447
|
+
],
|
|
448
|
+
},
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
### Label (label) [Required]
|
|
452
|
+
|
|
453
|
+
Label to be displayed in the payment modal. If other payment methods (Samsung Pay and/or Google Pay) are active, this can be set in `payment_options.label` to unify settings between multiple payments. Here is an example:
|
|
454
|
+
|
|
455
|
+
```javascript
|
|
456
|
+
apple_pay: {
|
|
457
|
+
label: 'Ali Hardware Store';
|
|
458
|
+
}
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
or
|
|
462
|
+
|
|
463
|
+
```javascript
|
|
464
|
+
payment_options: {
|
|
465
|
+
label: 'Ali Hardware Store';
|
|
466
|
+
}
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
### Merchant Validation URL (validate_merchant_url) [Optional]
|
|
470
|
+
|
|
471
|
+
This URL is used to initiate the Apple Pay session. A `POST` request will made
|
|
472
|
+
to the specified endpoint with a `JSON` object containing the URL. Here is the `JSON`
|
|
473
|
+
snippet:
|
|
474
|
+
|
|
475
|
+
```json
|
|
476
|
+
{
|
|
477
|
+
"validation_url": "https://url.to.applepay.tld/something/somthing"
|
|
478
|
+
}
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
The endpoint must return a response with the header `Content-Type: application/json` and
|
|
482
|
+
the response return from Apple as is.
|
|
483
|
+
|
|
484
|
+
Here is the configuration example:
|
|
485
|
+
|
|
486
|
+
```javascript
|
|
487
|
+
apple_pay: {
|
|
488
|
+
validate_merchant_url: 'https://mystore.test/applepay/validate-merchant';
|
|
489
|
+
}
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
### Supported Countries (supported_countries) [Optional]
|
|
493
|
+
|
|
494
|
+
An array of countries that cards are allowed from.
|
|
495
|
+
|
|
496
|
+
Default: `['SA']`. Only Saudi Arabia is enabled by default to prevent fraudulent transactions, you may enable more countries at your own risk.
|
|
497
|
+
|
|
498
|
+
```javascript
|
|
499
|
+
apple_pay: {
|
|
500
|
+
supported_countries: ['SA', 'US'];
|
|
501
|
+
}
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
## Google Pay Configurations (google_pay) [Required if Google Pay is activated]
|
|
505
|
+
|
|
506
|
+
This is an object that contains Google Pay specific configurations. Here is
|
|
507
|
+
an example:
|
|
508
|
+
|
|
509
|
+
```javascript
|
|
510
|
+
google_pay: {
|
|
511
|
+
// Google Pay Configurations
|
|
512
|
+
}
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
### Service ID (merchant_id) [Required]
|
|
516
|
+
|
|
517
|
+
This is used to specify Google Pay unique merchant ID:
|
|
518
|
+
|
|
519
|
+
```javascript
|
|
520
|
+
google_pay: {
|
|
521
|
+
merchant_id: 'dcc1cbb25d6a470bb42926';
|
|
522
|
+
}
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
### Label (label) [Required]
|
|
526
|
+
|
|
527
|
+
Label to be displayed in the payment modal. If other payment methods (Samsung Pay and/or Apple Pay) are active, this can be set in `payment_options.label` to unify settings between multiple payments. Here is an example:
|
|
528
|
+
|
|
529
|
+
```javascript
|
|
530
|
+
google_pay: {
|
|
531
|
+
label: 'Ali Hardware Store';
|
|
532
|
+
}
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
or
|
|
536
|
+
|
|
537
|
+
```javascript
|
|
538
|
+
payment_options: {
|
|
539
|
+
label: 'Ali Hardware Store';
|
|
540
|
+
}
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
### Country (country) [Required]
|
|
544
|
+
|
|
545
|
+
Google Pay merchant country. If other payment methods (Samsung Pay and/or Apple Pay) are active, this can be set in `payment_options.country` to unify settings between multiple payments.
|
|
546
|
+
|
|
547
|
+
```javascript
|
|
548
|
+
google_pay: {
|
|
549
|
+
country: 'SA';
|
|
550
|
+
}
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
or
|
|
554
|
+
|
|
555
|
+
```javascript
|
|
556
|
+
payment_options: {
|
|
557
|
+
country: 'SA';
|
|
558
|
+
}
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
### Gateway Merchant ID (gateway_merchant_id) [Optional]
|
|
562
|
+
|
|
563
|
+
A optional string that can be used to provide ID provided by your merchant gateway.
|
|
564
|
+
|
|
565
|
+
```javascript
|
|
566
|
+
google_pay: {
|
|
567
|
+
gateway_merchant_id: 'YOUR_GATEWAY_MERCHANT_ID';
|
|
568
|
+
}
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
### Environment (environment) [Optional]
|
|
572
|
+
|
|
573
|
+
A optional string that can be either `TEST` or `PRODUCTION` to manually define payment environment. Defaults value: `PRODUCTION`.
|
|
574
|
+
|
|
575
|
+
```javascript
|
|
576
|
+
google_pay: {
|
|
577
|
+
environment: 'TEST';
|
|
578
|
+
}
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
## Samsung Pay Configurations (samsung_pay) [Required if Samsung Pay is activated]
|
|
582
|
+
|
|
583
|
+
This is an object that contains Samsung Pay specific configurations. Here is
|
|
584
|
+
an example:
|
|
585
|
+
|
|
586
|
+
```javascript
|
|
587
|
+
samsung_pay: {
|
|
588
|
+
// Samsung Pay Configurations
|
|
589
|
+
}
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
### Service ID (service_id) [Required]
|
|
593
|
+
|
|
594
|
+
This is used to specify Samsung Pay unique merchant ID:
|
|
595
|
+
|
|
596
|
+
```javascript
|
|
597
|
+
samsung_pay: {
|
|
598
|
+
service_id: 'dcc1cbb25d6a470bb42926';
|
|
599
|
+
}
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
### Label (label) [Required]
|
|
603
|
+
|
|
604
|
+
Label to be displayed in the payment modal. If other payment methods (Apple Pay and/or Google Pay) are active, this can be set in `payment_options.label` to unify settings between multiple payments. Here is an example:
|
|
605
|
+
|
|
606
|
+
```javascript
|
|
607
|
+
samsung_pay: {
|
|
608
|
+
label: 'Ali Hardware Store';
|
|
609
|
+
}
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
or
|
|
613
|
+
|
|
614
|
+
```javascript
|
|
615
|
+
payment_options: {
|
|
616
|
+
label: 'Ali Hardware Store';
|
|
617
|
+
}
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
### Country (country) [Required]
|
|
621
|
+
|
|
622
|
+
Samsung Pay merchant country. If other payment methods (Apple Pay and/or Google Pay) are active, this can be set in `payment_options.country` to unify settings between multiple payments.
|
|
623
|
+
|
|
624
|
+
```javascript
|
|
625
|
+
samsung_pay: {
|
|
626
|
+
country: 'SA';
|
|
627
|
+
}
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
or
|
|
631
|
+
|
|
632
|
+
```javascript
|
|
633
|
+
payment_options: {
|
|
634
|
+
country: 'SA';
|
|
635
|
+
}
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
### Order Number (order_number) [Required]
|
|
639
|
+
|
|
640
|
+
Order number of the transaction.
|
|
641
|
+
|
|
642
|
+
```javascript
|
|
643
|
+
samsung_pay: {
|
|
644
|
+
order_number: 'DSTRF3457dsgTY';
|
|
645
|
+
}
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
### Version (version) [Optional]
|
|
649
|
+
|
|
650
|
+
This is used to specify Samsung Pay version. Default is `2`. Here is an example:
|
|
651
|
+
|
|
652
|
+
```javascript
|
|
653
|
+
samsung_pay: {
|
|
654
|
+
version: 2;
|
|
655
|
+
}
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
### ID (id) [Optional]
|
|
659
|
+
|
|
660
|
+
This is the id value registered with Moyasar
|
|
661
|
+
|
|
662
|
+
```javascript
|
|
663
|
+
samsung_pay: {
|
|
664
|
+
id: 'idProvidedByPG';
|
|
665
|
+
}
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
### Environment (environment) [Optional]
|
|
669
|
+
|
|
670
|
+
A optional string that can be either `STAGE` or `PRODUCTION` to manually define payment environment. Defaults value: `PRODUCTION`.
|
|
671
|
+
|
|
672
|
+
```javascript
|
|
673
|
+
samsung_pay: {
|
|
674
|
+
environment: 'STAGE';
|
|
675
|
+
}
|
|
676
|
+
```
|
|
677
|
+
|
|
678
|
+
### Payment Options (payment_options) [Optional]
|
|
679
|
+
|
|
680
|
+
Optional object to share data between different payments methods.
|
|
681
|
+
|
|
682
|
+
```javascript
|
|
683
|
+
payment_options: {
|
|
684
|
+
label: 'Ali Hardware Store',
|
|
685
|
+
country: 'SA',
|
|
686
|
+
}
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
# Contribution
|
|
690
|
+
|
|
691
|
+
Please feel free to improve on this library by making a PR.
|
|
692
|
+
|
|
693
|
+
# License
|
|
694
|
+
|
|
695
|
+
This software is licensed under the [MIT](LICENSE.md) license.
|