@tap-payments/apple-pay-button 0.0.3-test → 0.0.5-test

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/README.md CHANGED
@@ -43,9 +43,7 @@ const App = () => {
43
43
  // required (The amount to be charged)
44
44
  amount: '12',
45
45
  // required (The currency of the amount)
46
- currency: 'KWD',
47
- // required (The description/label of the transaction)
48
- label: 'to Merchant'
46
+ currency: 'KWD'
49
47
  }}
50
48
  // optional (The scope of the SDK and it can be one of these scopes:
51
49
  // [TapToken,AppleToken], by default it is TapToken)
@@ -110,7 +108,6 @@ const App = () => {
110
108
  | merchant.domain | `string` | `required` | The merchant domain name |
111
109
  | transaction.amount | `string` | `required` | The amount to be charged |
112
110
  | transaction.currency | `string` | `required` | The currency of the amount |
113
- | transaction.label | `string` | `required` | The description/label of the transaction |
114
111
  | scope | `Scope` | `optional` | The scope of the SDK |
115
112
  | supportedNetworks | `SupportedNetworks[]` | `optional` | The supported networks for the Apple Pay button |
116
113
  | buttonStyle | `ButtonStyle` | `optional` | The style of the Apple Pay button |
@@ -41,7 +41,6 @@ export interface ApplePayButtonProps {
41
41
  transaction: {
42
42
  amount: string;
43
43
  currency: string;
44
- label: string;
45
44
  };
46
45
  onCancel?: () => void;
47
46
  onError?: (error: any) => void;
@@ -17,5 +17,10 @@ export declare const SupportedNetworks: {
17
17
  readonly Mada: "mada";
18
18
  readonly MasterCard: "masterCard";
19
19
  readonly Visa: "visa";
20
+ readonly ChinaUnionPay: "chinaUnionPay";
21
+ readonly Discover: "discover";
22
+ readonly Electron: "electron";
23
+ readonly Jcb: "jcb";
24
+ readonly Maestro: "maestro";
20
25
  };
21
26
  export declare const ApplePayVersion = 5;
@@ -16,6 +16,11 @@ export var SupportedNetworks = {
16
16
  Amex: 'amex',
17
17
  Mada: 'mada',
18
18
  MasterCard: 'masterCard',
19
- Visa: 'visa'
19
+ Visa: 'visa',
20
+ ChinaUnionPay: 'chinaUnionPay',
21
+ Discover: 'discover',
22
+ Electron: 'electron',
23
+ Jcb: 'jcb',
24
+ Maestro: 'maestro'
20
25
  };
21
26
  export var ApplePayVersion = 5;
@@ -87,14 +87,15 @@ export var useApplePay = function (_a) {
87
87
  return [2];
88
88
  }
89
89
  try {
90
- paymentMethod = getApplePayPaymentMethod((profileData === null || profileData === void 0 ? void 0 : profileData.payment_options.payment_methods) || []);
90
+ paymentMethod = getApplePayPaymentMethod(profileData.payment_options.payment_methods || []);
91
91
  currency = validateCurrency(transaction.currency, paymentMethod.supported_currencies);
92
92
  cardBrands = validateSupportedNetworks(paymentMethod.supported_card_brands, supportedNetworks);
93
93
  request = getApplePayRequest({
94
94
  countryCode: profileData.merchant.country_code,
95
95
  transaction: __assign(__assign({}, transaction), { currency: currency }),
96
96
  billingContact: billingContact,
97
- supportedNetworks: cardBrands
97
+ supportedNetworks: cardBrands,
98
+ name: profileData.merchant.name
98
99
  });
99
100
  console.info("Creating ApplePaySession with version: ".concat(ApplePayVersion, " and request: ").concat(JSON.stringify(request)));
100
101
  session_1 = new ApplePaySession(ApplePayVersion, request);
@@ -105,6 +106,7 @@ export var useApplePay = function (_a) {
105
106
  case 0:
106
107
  console.info('Creating merchant session and validating merchant session');
107
108
  console.info('onvalidatemerchant event', event);
109
+ setLoading(true);
108
110
  _a.label = 1;
109
111
  case 1:
110
112
  _a.trys.push([1, 3, , 4]);
@@ -119,9 +121,11 @@ export var useApplePay = function (_a) {
119
121
  case 3:
120
122
  error_1 = _a.sent();
121
123
  console.error('error in onvalidatemerchant', error_1);
122
- session_1.completePayment({ status: 'STATUS_FAILURE' });
124
+ session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
123
125
  throw error_1;
124
- case 4: return [2];
126
+ case 4:
127
+ setLoading(false);
128
+ return [2];
125
129
  }
126
130
  });
127
131
  }); };
@@ -130,6 +134,7 @@ export var useApplePay = function (_a) {
130
134
  return __generator(this, function (_b) {
131
135
  switch (_b.label) {
132
136
  case 0:
137
+ setLoading(true);
133
138
  console.info('onpaymentauthorized event', event);
134
139
  _b.label = 1;
135
140
  case 1:
@@ -143,7 +148,7 @@ export var useApplePay = function (_a) {
143
148
  case 2: return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(event.payment.token.paymentData))];
144
149
  case 3:
145
150
  _b.sent();
146
- session_1.completePayment({ status: 'STATUS_SUCCESS' });
151
+ session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
147
152
  return [3, 8];
148
153
  case 4: return [4, appService.tapTokenization(event.payment.token.paymentData, profileData.merchant)];
149
154
  case 5:
@@ -151,25 +156,27 @@ export var useApplePay = function (_a) {
151
156
  return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data))];
152
157
  case 6:
153
158
  _b.sent();
154
- session_1.completePayment({ status: 'STATUS_SUCCESS' });
159
+ session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
155
160
  return [3, 8];
156
161
  case 7:
157
162
  console.error('We only support AppleToken and TapToken for now');
158
163
  console.info('Completing payment with status: STATUS_FAILURE');
159
- session_1.completePayment({ status: 'STATUS_FAILURE' });
164
+ session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
160
165
  _b.label = 8;
161
166
  case 8: return [3, 10];
162
167
  case 9:
163
168
  error_2 = _b.sent();
164
169
  console.error('error in onpaymentauthorized', error_2);
165
- session_1.completePayment({ status: 'STATUS_FAILURE' });
170
+ session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
166
171
  throw error_2;
167
- case 10: return [2];
172
+ case 10:
173
+ setLoading(false);
174
+ return [2];
168
175
  }
169
176
  });
170
177
  }); };
171
- session_1.oncancel = function () {
172
- console.info('oncancel event');
178
+ session_1.oncancel = function (event) {
179
+ console.info('oncancel event', event);
173
180
  if (onCancel)
174
181
  onCancel();
175
182
  };
@@ -1,8 +1,9 @@
1
1
  import { ApplePayButtonProps, ApplePayRequestData, PaymentMethod } from '../@types';
2
2
  import { SupportedNetworks } from '../constants';
3
- export declare const validateSupportedNetworks: (supportedNetworksConfig: Array<(typeof SupportedNetworks)[keyof typeof SupportedNetworks]>, supportedNetworks: ApplePayButtonProps['supportedNetworks']) => ("amex" | "mada" | "masterCard" | "visa")[];
3
+ export declare const validateSupportedNetworks: (supportedNetworksConfig: Array<(typeof SupportedNetworks)[keyof typeof SupportedNetworks]>, supportedNetworks: ApplePayButtonProps['supportedNetworks']) => ("amex" | "mada" | "masterCard" | "visa" | "chinaUnionPay" | "discover" | "electron" | "jcb" | "maestro")[];
4
4
  export declare const validateCurrency: (currency: string, currencies: string[]) => string;
5
- export declare const getApplePayRequest: ({ transaction, billingContact, supportedNetworks, countryCode }: Pick<ApplePayButtonProps, "supportedNetworks" | "transaction" | "billingContact"> & {
5
+ export declare const getApplePayRequest: ({ transaction, billingContact, supportedNetworks, countryCode, name }: Pick<ApplePayButtonProps, "supportedNetworks" | "transaction" | "billingContact"> & {
6
6
  countryCode: string;
7
+ name: string;
7
8
  }) => ApplePayRequestData;
8
9
  export declare const getApplePayPaymentMethod: (paymentMethods: Array<PaymentMethod>) => PaymentMethod;
@@ -24,7 +24,7 @@ export var validateCurrency = function (currency, currencies) {
24
24
  return currency;
25
25
  };
26
26
  export var getApplePayRequest = function (_a) {
27
- var transaction = _a.transaction, billingContact = _a.billingContact, supportedNetworks = _a.supportedNetworks, countryCode = _a.countryCode;
27
+ var transaction = _a.transaction, billingContact = _a.billingContact, supportedNetworks = _a.supportedNetworks, countryCode = _a.countryCode, name = _a.name;
28
28
  return {
29
29
  countryCode: countryCode,
30
30
  currencyCode: transaction.currency,
@@ -38,7 +38,7 @@ export var getApplePayRequest = function (_a) {
38
38
  },
39
39
  total: {
40
40
  amount: Number(transaction.amount),
41
- label: transaction.label
41
+ label: name
42
42
  }
43
43
  };
44
44
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/apple-pay-button",
3
- "version": "0.0.3-test",
3
+ "version": "0.0.5-test",
4
4
  "description": "Apple Pay Button React Component",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.js",