@tap-payments/apple-pay-button 0.0.21-test → 0.0.22-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
@@ -129,74 +129,57 @@ const App = () => {
129
129
  <script type="text/javascript">
130
130
  const { renderApplePayButton, ButtonStyle, Scope, SupportedNetworks, Locale, ButtonType } = window.TapSDKs
131
131
  renderApplePayButton(
132
- {
133
- // required
134
- publicKey: 'pk_test_xxxxxxxxxxxxxxxzh',
135
- // optional (The environment of the SDK and it can be one of these Environment)
136
- environment: Environment.Development,
137
- // optional (to enable the debug mode)
138
- debug: true,
139
- // required (The merchant identifier provided by Tap)
140
- merchantIdentifier: 'merchant.tap.applepay.test',
141
- merchant: {
142
- // required
143
- domain: 'example.com'
144
- // optional
145
- // id: '123...'
146
- },
147
- // required
148
- transaction: {
149
- // required
150
- currency: 'USD',
151
- // required
152
- amount: '100'
153
- },
154
- // optional
155
- scope: Scope.TapToken,
156
- // optional
157
- buttonStyle: ButtonStyle.WhiteOutline,
158
- // optional (The locale of the Apple Pay button and it can be one of these locales)
159
- locale: Locale.EN,
160
- // optional (The type of the Apple Pay button and it can be one of these types)
161
- type: ButtonType.PLAIN,
162
- // optional
163
- supportedNetworks: [SupportedNetworks.Visa, SupportedNetworks.MasterCard],
164
- // optional (The billing contact information)
165
- billingContact: {
166
- // required
167
- email: {
168
- // required
169
- address: 'test@gmail.com'
170
- },
171
- // required
172
- name: {
173
- // required
174
- first: 'test',
175
- // required
176
- last: 'tester',
177
- // optional
178
- middle: 'test'
179
- },
180
- // required
181
- phone: {
182
- number: '10XXXXXX56',
183
- code: '+20'
184
- }
185
- },
186
- // optional
187
- onCancel: () => {
188
- console.log('onCancel')
189
- },
190
- // optional
191
- onError: (error) => {
192
- console.log('onError', error)
193
- },
194
- // optional
195
- onSuccess: async (data) => {
196
- console.log('onSuccess', data)
197
- }
198
- },
199
- 'apple-pay-button'
132
+ {
133
+ publicKey: 'pk_test_7xxxxxxxxx',
134
+ merchantIdentifier: 'merchant.com.xxxxx',
135
+ environment: Environment.Sandbox,
136
+ merchant: {
137
+ domain: 'tp-txxxxxxxx',
138
+
139
+ id: 'merchant_xxxxxxxxxx"
140
+ },
141
+
142
+ transaction: {
143
+
144
+ currency: 'SAR',
145
+
146
+ amount: '3'
147
+ },
148
+
149
+ scope: Scope.TapToken,
150
+ buttonStyle: ButtonStyle.Black,
151
+ type: ButtonType.PLAIN,
152
+ locale: Locale.EN,
153
+ supportedNetworks: [SupportedNetworks.Visa, SupportedNetworks.MasterCard, SupportedNetworks.Mada],
154
+ billingContact: {
155
+ email: {
156
+
157
+ address: 'test`@gmail.com'
158
+ },
159
+ name: {
160
+ first: 'test',
161
+ last: 'test',
162
+ middle: '123'
163
+ },
164
+ phone: {
165
+ number: '555555555',
166
+ code: '966'
167
+ }
168
+ },
169
+ onCancel: async () => {
170
+ console.log('onCancel')
171
+ },
172
+ onError: async (error) => {
173
+ console.log('onError', error)
174
+ },
175
+ onSuccess: async (data) => {
176
+ console.log('onSuccess', data)
177
+ },
178
+ onReady: async () => {
179
+ console.log('onReady')
180
+ }
181
+ },
182
+ 'apple-pay-button'
200
183
  )
201
184
  </script>
202
185
  </body>
@@ -80,3 +80,32 @@ export interface MetaData {
80
80
  payment_options: PaymentOptionsResponse;
81
81
  headers: Record<string, string>;
82
82
  }
83
+ export interface CheckoutProfileRequest {
84
+ currency: string;
85
+ merchant_id: string;
86
+ total_amount: number;
87
+ order: {
88
+ amount: number;
89
+ currency: string;
90
+ customer?: {
91
+ id: string;
92
+ email: string;
93
+ first_name: string;
94
+ last_name: string;
95
+ phone: {
96
+ country_code: string;
97
+ number: string;
98
+ };
99
+ };
100
+ items: {
101
+ quantity: number;
102
+ amount: number;
103
+ currency: string;
104
+ name: string;
105
+ requiresShipping: string;
106
+ }[];
107
+ merchant: {
108
+ id: string;
109
+ };
110
+ };
111
+ }
@@ -1,4 +1,4 @@
1
- import { MerchantResponse, ApplePayButtonProps } from '../@types';
1
+ import { MerchantResponse, ApplePayButtonProps, CheckoutProfileRequest } from '../@types';
2
2
  import BaseService from './base';
3
3
  declare class APPService extends BaseService {
4
4
  private baseUrl;
@@ -12,7 +12,7 @@ declare class APPService extends BaseService {
12
12
  pk: string;
13
13
  domain: string;
14
14
  }): Promise<void>;
15
- checkoutProfile(merchantId?: string): Promise<{
15
+ checkoutProfile(request: CheckoutProfileRequest): Promise<{
16
16
  merchant: any;
17
17
  payment_options: any;
18
18
  }>;
@@ -176,12 +176,12 @@ var APPService = (function (_super) {
176
176
  enumerable: false,
177
177
  configurable: true,
178
178
  writable: true,
179
- value: function (merchantId) {
179
+ value: function (request) {
180
180
  return __awaiter(this, void 0, void 0, function () {
181
181
  var data, merchant, payment_options, session;
182
182
  return __generator(this, function (_a) {
183
183
  switch (_a.label) {
184
- case 0: return [4, this.post(this.baseUrl + '/checkoutprofile', { merchant_id: merchantId !== null && merchantId !== void 0 ? merchantId : '' })];
184
+ case 0: return [4, this.post(this.baseUrl + '/checkoutprofile', request)];
185
185
  case 1:
186
186
  data = (_a.sent()).data;
187
187
  if (data.errors)
@@ -57,15 +57,16 @@ export var useApplePay = function (_a) {
57
57
  var _d = useState(false), disabled = _d[0], setDisabled = _d[1];
58
58
  var initialize = useCallback(function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
59
59
  var merchantProfile, payment_options, headers, data, err_1;
60
- return __generator(this, function (_a) {
61
- switch (_a.label) {
60
+ var _a, _b;
61
+ return __generator(this, function (_c) {
62
+ switch (_c.label) {
62
63
  case 0:
63
64
  setLoading(true);
64
65
  appService.setEnv(environment);
65
66
  appService.setBaseUrl();
66
- _a.label = 1;
67
+ _c.label = 1;
67
68
  case 1:
68
- _a.trys.push([1, 4, 5, 6]);
69
+ _c.trys.push([1, 4, 5, 6]);
69
70
  if (metaData) {
70
71
  merchantProfile = metaData.merchant, payment_options = metaData.payment_options, headers = metaData.headers;
71
72
  setAxiosGlobalHeaders(__assign({}, headers));
@@ -74,16 +75,42 @@ export var useApplePay = function (_a) {
74
75
  }
75
76
  return [4, appService.setBrowserHeaders({ locale: locale, domain: merchant.domain, pk: publicKey })];
76
77
  case 2:
77
- _a.sent();
78
- return [4, appService.checkoutProfile()];
78
+ _c.sent();
79
+ return [4, appService.checkoutProfile({
80
+ currency: transaction.currency,
81
+ merchant_id: (_a = merchant.id) !== null && _a !== void 0 ? _a : '',
82
+ total_amount: Number(transaction.amount),
83
+ order: __assign(__assign({ amount: Number(transaction.amount), currency: transaction.currency }, (billingContact && {
84
+ customer: {
85
+ id: '',
86
+ email: billingContact.email.address,
87
+ first_name: billingContact.name.first,
88
+ last_name: billingContact.name.last,
89
+ phone: {
90
+ country_code: billingContact.phone.code,
91
+ number: billingContact.phone.number
92
+ }
93
+ }
94
+ })), { merchant: {
95
+ id: (_b = merchant.id) !== null && _b !== void 0 ? _b : ''
96
+ }, items: [
97
+ {
98
+ amount: Number(transaction.amount),
99
+ currency: transaction.currency,
100
+ name: 'apple pay sdk order item',
101
+ quantity: 1,
102
+ requiresShipping: 'no'
103
+ }
104
+ ] })
105
+ })];
79
106
  case 3:
80
- data = _a.sent();
107
+ data = _c.sent();
81
108
  if (debug)
82
109
  console.log('merchant configuration: ', data);
83
110
  setProfile(data);
84
111
  return [3, 6];
85
112
  case 4:
86
- err_1 = _a.sent();
113
+ err_1 = _c.sent();
87
114
  onError && onError(err_1.errors || err_1);
88
115
  return [3, 6];
89
116
  case 5:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/apple-pay-button",
3
- "version": "0.0.21-test",
3
+ "version": "0.0.22-test",
4
4
  "description": "Apple Pay Button React Component",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.js",