You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Constructs a PaymentRequest object for creating a payment.
5
6
* @param {givenId | null} [givenId] - Optional UUID for the payment (UUID v4 is recommended). It will be attached with the payment creation request to support idempotency. `It is going be the ID of the created payment`.
7
+
* @param {string} [baseUrl='https://api.moyasar.com'] - The base URL for Moyasar API. Defaults to 'https://api.moyasar.com'.
6
8
* @param {number} amount - The amount to be charged in the smallest currency unit. For example, to charge `SAR 257.58` you will have the [amount] as `25758`. In other words, 10 SAR = 10 * 100 Halalas. Integer values only.
7
9
* @param {string} [currency='SAR'] - The currency code for the payment. Defaults to 'SAR'. Must be in ISO 4217 3-letter currency code format.
8
10
* @param {string | null} [description] - Can be any string you want to tag the payment. For example `Payment for Order #34321`.
9
11
* @param {Record<string, string | number | boolean> | null} [metadata] - Adds searchable key/value pairs to the payment. For example `{"size": "xl"}`.
10
12
* @param {PaymentRequestSource} source - A payment source object to be charged, such as Apple Pay source or Credit Card source.
11
13
* @param {string | null} [callbackUrl] - The URL to be redirected to after a 3D secure transaction (e.g., https://sdk.moyasar.com/return). Required for Credit Card payments.
12
14
* @param {boolean} [applyCoupon=true] - A flag to control the coupon application (based on the BIN). This key is required only if you don't want to apply the coupon. Otherwise, the coupon is going to be applied. Defaults to true.
15
+
* @param {PaymentSplit[] | null} [splits] - Optional array of `PaymentSplit` object used to distribute the charged amount (in the smallest currency unit) among multiple recipients or to collect a platform fee.
16
+
* - Each split requires `recipientId` and `amount` parameters.
17
+
* - `reference` and `description` parameters are optional.
18
+
* - Set `feeSource = true` parameter to mark the split as a fee/commission taken by the platform.
19
+
* - Set `refundable` parameter to control whether a split amount is refundable (`true`/`false`). Leave it to use the backend's default.
20
+
* - Set the `publishableApiKey` to "pk_test_uQra5pwtUo9GaenMSS4XgfAmeLhmjUTJwFdXJxsH" and set the `baseUrl` parameter to "https://apimig.moyasar.com" for staging testing.
@@ -9,6 +10,7 @@ import type { SamsungPayConfig } from './samsung_pay_config';
9
10
exportclassPaymentConfig{
10
11
givenId?: string|null;
11
12
publishableApiKey: string;
13
+
baseUrl: string;
12
14
amount: number;
13
15
merchantCountryCode: string;
14
16
currency: string;
@@ -20,11 +22,13 @@ export class PaymentConfig {
20
22
createSaveOnlyToken: boolean;
21
23
samsungPay?: SamsungPayConfig;
22
24
applyCoupon?: boolean;
25
+
splits?: PaymentSplit[]|null;
23
26
24
27
/**
25
28
* Constructs a new PaymentConfig instance with the provided settings.
26
29
* @param givenId - Optional UUID for the payment (UUID v4 is recommended). It will be attached with the payment creation request to support idempotency. `It is going be the ID of the created payment`.
27
30
* @param publishableApiKey - Your Moyasar publishable API key - https://docs.moyasar.com/get-your-api-keys.
31
+
* @param baseUrl - Moyasar API base URL. Defaults to `https://api.moyasar.com`.
28
32
* @param amount - The amount to be charged in the smallest currency unit. For example, to charge `SAR 257.58` you will have the [amount] as `25758`. In other words, 10 SAR = 10 * 100 Halalas. Integer values only.
29
33
* @param merchantCountryCode - The country code of the merchant’s principle place of business. Defaults to 'SA'. Must be in ISO 3166-1 alpha-2 country code format.
30
34
* @param currency - The currency code for the payment. Defaults to 'SAR'. Must be in ISO 4217 3-letter currency code format.
@@ -36,10 +40,17 @@ export class PaymentConfig {
36
40
* @param createSaveOnlyToken - Optional to process a save only token flow for a Credit Card. Defaults to false - https://docs.moyasar.com/create-token
37
41
* @param samsungPay - Required for Samsung Pay feature.
38
42
* @param applyCoupon - A flag to control the coupon application (based on the BIN). This key is required only if you don't want to apply the coupon. Otherwise, the coupon is going to be applied. Defaults to true.
43
+
* @param splits - Optional array of `PaymentSplit` object used to distribute the charged amount (in the smallest currency unit) among multiple recipients or to collect a platform fee.
44
+
* - Each split requires `recipientId` and `amount` parameters.
45
+
* - `reference` and `description` parameters are optional.
46
+
* - Set `feeSource = true` parameter to mark the split as a fee/commission taken by the platform.
47
+
* - Set `refundable` parameter to control whether a split amount is refundable (`true`/`false`). Leave it to use the backend's default.
48
+
* - Set the `publishableApiKey` parameter to "pk_test_uQra5pwtUo9GaenMSS4XgfAmeLhmjUTJwFdXJxsH" and set the `baseUrl` parameter to "https://apimig.moyasar.com" for staging testing.
39
49
*/
40
50
constructor({
41
51
givenId,
42
52
publishableApiKey,
53
+
baseUrl ='https://api.moyasar.com',
43
54
amount,
44
55
merchantCountryCode ='SA',
45
56
currency ='SAR',
@@ -51,9 +62,11 @@ export class PaymentConfig {
51
62
createSaveOnlyToken =false,
52
63
samsungPay,
53
64
applyCoupon =true,
65
+
splits,
54
66
}: {
55
67
givenId?: string|null;
56
68
publishableApiKey: string;
69
+
baseUrl?: string;
57
70
amount: number;
58
71
merchantCountryCode?: string;
59
72
currency?: string;
@@ -65,6 +78,7 @@ export class PaymentConfig {
65
78
createSaveOnlyToken?: boolean;
66
79
samsungPay?: SamsungPayConfig;
67
80
applyCoupon?: boolean;
81
+
splits?: PaymentSplit[]|null;
68
82
}){
69
83
assert(
70
84
publishableApiKey.length>0,
@@ -85,9 +99,13 @@ export class PaymentConfig {
85
99
supportedNetworks.length>0,
86
100
'At least 1 network must be supported.'
87
101
);
102
+
assert(baseUrl.length>0,'Please fill `baseUrl` argument.');
* @param splits - Optional array of `PaymentSplit` object used to distribute the charged amount (in the smallest currency unit) among multiple recipients or to collect a platform fee.
3
+
* - Each split requires `recipientId` and `amount` parameters.
4
+
* - `reference` and `description` parameters are optional.
5
+
* - Set `feeSource = true` parameter to mark the split as a fee/commission taken by the platform.
6
+
* - Set `refundable` parameter to control whether a split amount is refundable (`true`/`false`). Leave it to use the backend's default.
7
+
* - Set the `publishableApiKey` parameter to "pk_test_uQra5pwtUo9GaenMSS4XgfAmeLhmjUTJwFdXJxsH" and set the `baseUrl` parameter to "https://apimig.moyasar.com" for staging testing.
0 commit comments