@tap-payments/apple-pay-button 1.2.1 → 1.2.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.
@@ -1,4 +1,4 @@
1
- import { Scope, SupportedNetworks, ButtonType, Locale, Environment, ThemeMode, Edges } from '../constants';
1
+ import { Scope, SupportedNetworks, ButtonType, Locale, Environment, ThemeMode, Edges, Integration } from '../constants';
2
2
  import { ApplePayPaymentContact, ApplePayPaymentMethod, ApplePayShippingMethod, ApplePayUpdateData, RequiredShippingContactField } from './ApplePaySession';
3
3
  export * from './ApplePaySession';
4
4
  export interface Interface {
@@ -59,6 +59,7 @@ export interface Features {
59
59
  supportsCouponCode?: boolean;
60
60
  }
61
61
  export interface ApplePayButtonProps {
62
+ integration?: typeof Integration[keyof typeof Integration];
62
63
  scope?: typeof Scope[keyof typeof Scope];
63
64
  publicKey: string;
64
65
  environment: typeof Environment[keyof typeof Environment];
@@ -102,6 +103,7 @@ export interface PaymentMethod {
102
103
  payment_type: string;
103
104
  supported_card_brands: Array<typeof SupportedNetworks[keyof typeof SupportedNetworks]>;
104
105
  supported_currencies: string[];
106
+ identifier?: string;
105
107
  }
106
108
  export interface PaymentOptionsResponse {
107
109
  id: string;
@@ -2,6 +2,10 @@ export declare const Scope: {
2
2
  readonly AppleToken: "AppleToken";
3
3
  readonly TapToken: "TapToken";
4
4
  };
5
+ export declare const Integration: {
6
+ readonly Webview: "Webview";
7
+ readonly Merchant: "Merchant";
8
+ };
5
9
  export declare const ButtonStyle: {
6
10
  readonly Black: "black";
7
11
  readonly White: "white";
@@ -58,3 +62,4 @@ export declare const RSA_STAGING_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMI
58
62
  export declare const RSA_BETA_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----";
59
63
  export declare const RSA_PRODUCTION_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----";
60
64
  export declare const APPLE_PAY_SCRIPT = "https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js";
65
+ export declare const FALLBACK_MERCHANT_IDENTIFIER = "merchant.tap.gosell";
@@ -2,6 +2,10 @@ export var Scope = {
2
2
  AppleToken: 'AppleToken',
3
3
  TapToken: 'TapToken'
4
4
  };
5
+ export var Integration = {
6
+ Webview: 'Webview',
7
+ Merchant: 'Merchant'
8
+ };
5
9
  export var ButtonStyle = {
6
10
  Black: 'black',
7
11
  White: 'white',
@@ -58,3 +62,4 @@ export var RSA_STAGING_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqG
58
62
  export var RSA_BETA_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----";
59
63
  export var RSA_PRODUCTION_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----";
60
64
  export var APPLE_PAY_SCRIPT = 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js';
65
+ export var FALLBACK_MERCHANT_IDENTIFIER = 'merchant.tap.gosell';
@@ -6,5 +6,5 @@ interface UseApplePayReturnProps {
6
6
  onApplePayButtonClicked: () => Promise<void>;
7
7
  abortApplePaySession: () => void;
8
8
  }
9
- export declare const useApplePay: ({ publicKey, merchant, transaction, interface: interfaceObj, customer, onCancel, onError, onSuccess, scope, acceptance, features, metaData, debug, environment, platform, onReady, onMerchantValidation, onShippingMethodSelected, onShippingContactSelected, onPaymentMethodSelected, onCouponChanged }: UseApplePayProps) => UseApplePayReturnProps;
9
+ export declare const useApplePay: ({ publicKey, merchant, transaction, interface: interfaceObj, customer, onCancel, onError, onSuccess, integration, scope, acceptance, features, metaData, debug, environment, platform, onReady, onMerchantValidation, onShippingMethodSelected, onShippingContactSelected, onPaymentMethodSelected, onCouponChanged }: UseApplePayProps) => UseApplePayReturnProps;
10
10
  export {};
@@ -58,13 +58,13 @@ var __rest = (this && this.__rest) || function (s, e) {
58
58
  };
59
59
  import { useCallback, useEffect, useState } from 'react';
60
60
  import appService from '../api/app.service';
61
- import { ApplePayVersion } from '../constants';
61
+ import { ApplePayVersion, FALLBACK_MERCHANT_IDENTIFIER, Integration } from '../constants';
62
62
  import { setAxiosGlobalHeaders } from '../api/httpClient';
63
63
  import { getApplePayPaymentMethod, getApplePayRequest, validateCurrency, validateSupportedNetworks } from '../utils/config';
64
64
  import { getMerchantCapaplities } from '../utils/defaultValues';
65
65
  import { useApplePayScript } from './useApplePayScript';
66
66
  export var useApplePay = function (_a) {
67
- var publicKey = _a.publicKey, merchant = _a.merchant, transaction = _a.transaction, interfaceObj = _a.interface, customer = _a.customer, onCancel = _a.onCancel, onError = _a.onError, onSuccess = _a.onSuccess, scope = _a.scope, acceptance = _a.acceptance, features = _a.features, metaData = _a.metaData, debug = _a.debug, environment = _a.environment, platform = _a.platform, onReady = _a.onReady, onMerchantValidation = _a.onMerchantValidation, onShippingMethodSelected = _a.onShippingMethodSelected, onShippingContactSelected = _a.onShippingContactSelected, onPaymentMethodSelected = _a.onPaymentMethodSelected, onCouponChanged = _a.onCouponChanged;
67
+ var publicKey = _a.publicKey, merchant = _a.merchant, transaction = _a.transaction, interfaceObj = _a.interface, customer = _a.customer, onCancel = _a.onCancel, onError = _a.onError, onSuccess = _a.onSuccess, integration = _a.integration, scope = _a.scope, acceptance = _a.acceptance, features = _a.features, metaData = _a.metaData, debug = _a.debug, environment = _a.environment, platform = _a.platform, onReady = _a.onReady, onMerchantValidation = _a.onMerchantValidation, onShippingMethodSelected = _a.onShippingMethodSelected, onShippingContactSelected = _a.onShippingContactSelected, onPaymentMethodSelected = _a.onPaymentMethodSelected, onCouponChanged = _a.onCouponChanged;
68
68
  var _b = useState(false), loading = _b[0], setLoading = _b[1];
69
69
  var _c = useState(null), profileData = _c[0], setProfile = _c[1];
70
70
  var _d = useState(false), disabled = _d[0], setDisabled = _d[1];
@@ -154,7 +154,7 @@ export var useApplePay = function (_a) {
154
154
  initialize(metaData);
155
155
  }, [isScriptLoaded, initialize, metaData]);
156
156
  var onApplePayButtonClicked = function () { return __awaiter(void 0, void 0, void 0, function () {
157
- var ApplePaySession, paymentMethod, currency, cardBrands, request, session_1;
157
+ var ApplePaySession, paymentMethod_1, currency, cardBrands, request, session_1;
158
158
  var _a;
159
159
  return __generator(this, function (_b) {
160
160
  ApplePaySession = window.ApplePaySession;
@@ -169,9 +169,9 @@ export var useApplePay = function (_a) {
169
169
  return [2];
170
170
  }
171
171
  try {
172
- paymentMethod = getApplePayPaymentMethod(profileData.payment_options.payment_methods || []);
173
- currency = validateCurrency(transaction.currency, paymentMethod.supported_currencies);
174
- cardBrands = validateSupportedNetworks(paymentMethod.supported_card_brands, acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedBrands);
172
+ paymentMethod_1 = getApplePayPaymentMethod(profileData.payment_options.payment_methods || []);
173
+ currency = validateCurrency(transaction.currency, paymentMethod_1.supported_currencies);
174
+ cardBrands = validateSupportedNetworks(paymentMethod_1.supported_card_brands, acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedBrands);
175
175
  request = getApplePayRequest({
176
176
  features: features,
177
177
  countryCode: profileData.merchant.country_code,
@@ -203,7 +203,9 @@ export var useApplePay = function (_a) {
203
203
  if (debug) {
204
204
  console.info("creating merchant session for merchantData: ".concat(JSON.stringify(profileData.merchant), " and validationURL: ").concat(event.validationURL, " and merchant.domain: ").concat(merchant.domain));
205
205
  }
206
- return [4, appService.appleSession(__assign(__assign({}, profileData.merchant), { id: merchant.id }), event.validationURL, merchant.domain, merchant.identifier || merchant.id)];
206
+ return [4, appService.appleSession(__assign(__assign({}, profileData.merchant), { id: merchant.id }), event.validationURL, merchant.domain, integration === Integration.Webview
207
+ ? paymentMethod_1.identifier || FALLBACK_MERCHANT_IDENTIFIER
208
+ : merchant.identifier || merchant.id)];
207
209
  case 2:
208
210
  merchantSession = _a.sent();
209
211
  if (debug)
@@ -228,7 +230,7 @@ export var useApplePay = function (_a) {
228
230
  });
229
231
  }); };
230
232
  session_1.onpaymentauthorized = function (event) { return __awaiter(void 0, void 0, void 0, function () {
231
- var _a, token, rest, newEvent, _b, _c, paymentData, paymentMethod_1, transactionIdentifier, data, error_2;
233
+ var _a, token, rest, newEvent, _b, _c, paymentData, paymentMethod_2, transactionIdentifier, data, error_2;
232
234
  var _d, _e;
233
235
  return __generator(this, function (_f) {
234
236
  switch (_f.label) {
@@ -253,8 +255,8 @@ export var useApplePay = function (_a) {
253
255
  session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
254
256
  return [3, 8];
255
257
  case 4:
256
- _c = (_e = event.payment.token) !== null && _e !== void 0 ? _e : {}, paymentData = _c.paymentData, paymentMethod_1 = _c.paymentMethod, transactionIdentifier = _c.transactionIdentifier;
257
- return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod_1, transactionIdentifier: transactionIdentifier }))];
258
+ _c = (_e = event.payment.token) !== null && _e !== void 0 ? _e : {}, paymentData = _c.paymentData, paymentMethod_2 = _c.paymentMethod, transactionIdentifier = _c.transactionIdentifier;
259
+ return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod_2, transactionIdentifier: transactionIdentifier }))];
258
260
  case 5:
259
261
  data = _f.sent();
260
262
  return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data, newEvent))];
@@ -6,6 +6,7 @@ export declare const getDefaultValues: (mainObject: ApplePayButtonProps) => {
6
6
  edges?: "straight" | "curved" | undefined;
7
7
  type?: "book" | "buy" | "check-out" | "pay" | "plain" | "subscribe" | undefined;
8
8
  };
9
+ integration?: "Webview" | "Merchant" | undefined;
9
10
  scope?: "AppleToken" | "TapToken" | undefined;
10
11
  publicKey: string;
11
12
  environment: "production" | "sandbox" | "beta" | "development" | "staging";
@@ -32,16 +32,17 @@ export var getDefaultValues = function (mainObject) {
32
32
  };
33
33
  export var getMerchantCapaplities = function (supportedCards) {
34
34
  var merchantCapaplities = [MerchantCapabilities.Supports3DS];
35
- if (!supportedCards) {
35
+ var lowerCaseSupportedCards = supportedCards === null || supportedCards === void 0 ? void 0 : supportedCards.map(function (card) { return card.toLocaleLowerCase(); });
36
+ if (!lowerCaseSupportedCards) {
36
37
  merchantCapaplities = __spreadArray(__spreadArray([], merchantCapaplities, true), [
37
38
  MerchantCapabilities.SupportsCredit,
38
39
  MerchantCapabilities.SupportsDebit
39
40
  ], false);
40
41
  }
41
- else if (supportedCards.includes('CREDIT')) {
42
+ else if (lowerCaseSupportedCards.includes('credit')) {
42
43
  merchantCapaplities.push(MerchantCapabilities.SupportsCredit);
43
44
  }
44
- else if (supportedCards.includes('DEBIT')) {
45
+ else if (lowerCaseSupportedCards.includes('debit')) {
45
46
  merchantCapaplities.push(MerchantCapabilities.SupportsDebit);
46
47
  }
47
48
  return merchantCapaplities;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/apple-pay-button",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "Apple Pay Button React Component",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.js",