@fat-zebra/sdk 1.5.3-beta.3 → 1.5.4

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.dev.md CHANGED
@@ -165,6 +165,28 @@ from here enter your 2FA code and voila! You have published a new version of the
165
165
 
166
166
  ## Release Management
167
167
 
168
+ ### Automated release:
169
+
170
+ To deploy to npm run this command:
171
+
172
+ ```
173
+ npm run npm:publish
174
+ ```
175
+
176
+ ![deployment options](deploy-menu.png)
177
+
178
+ The semantic version will be bumped according to the selected release type.
179
+
180
+ | Release type | version |
181
+ |--------------|--------------|
182
+ | Major | x-0-0 |
183
+ | Minor | 0-x-0 |
184
+ | Patch | 0-0-x |
185
+ | Beta | 0-0-0-beta-x |
186
+
187
+ The publish script will also tag the release and push to the current branch.
188
+ This process is an automated version of the process below, excluding changelog
189
+
168
190
  The release of the sdk follows a weekly schedule. In the beginning of a new release cycle, do the following
169
191
 
170
192
  1. Create a release branch, release/vX.X.X
Binary file
@@ -0,0 +1,28 @@
1
+ import { PaymentRequest } from './clients/apple-pay-client';
2
+ import * as payNow from './clients/paynow-client';
3
+ import { PostMessage } from '../shared/post-message-client';
4
+ declare class ApplePayManager {
5
+ private merchantId;
6
+ private canMakePayments;
7
+ private iframe;
8
+ private applePaySession;
9
+ private postMessageClient;
10
+ private fzPayNowDomain;
11
+ private username?;
12
+ private token?;
13
+ constructor(config: {
14
+ iframe: HTMLIFrameElement;
15
+ fzPayNowDomain: string;
16
+ username?: string;
17
+ token?: string;
18
+ });
19
+ initialize(): Promise<void>;
20
+ checkApplePayEligibility(): void;
21
+ notifyApplePayEligibility(): void;
22
+ registerEventListener(): Promise<void>;
23
+ purchase(request: PaymentRequest): Promise<void>;
24
+ extractApplePaymentRequestParams(payload: any): PaymentRequest;
25
+ extractPayNowPaymentAttributes(payload: any): payNow.PaymentAttributes;
26
+ sendMessage(payload: PostMessage): void;
27
+ }
28
+ export default ApplePayManager;
@@ -0,0 +1,115 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { createSession, getEligibilty, } from './clients/apple-pay-client';
11
+ import * as payNow from './clients/paynow-client';
12
+ import { PostMessageClient } from '../shared/post-message-client';
13
+ // import * as process from "process";
14
+ const channel = 'applepay';
15
+ // const fzPayNowDomain = process.env.PAYNOW_BASE_URL
16
+ // do the domain handling stuff better
17
+ const paynowDomain = 'https://paynow.test';
18
+ const merchantSessionPath = '/v2/apple_pay/payment_session';
19
+ const purchaseTokenPath = '/v2/apple_pay/token';
20
+ class ApplePayManager {
21
+ constructor(config) {
22
+ // if (!config.fzPayNowDomain) {
23
+ // console.log('hitting i here')
24
+ // this.fzPayNowDomain = process?.env?.PAYNOW_BASE_URL;
25
+ // } else {
26
+ this.fzPayNowDomain = config.fzPayNowDomain;
27
+ this.username = config.username;
28
+ this.token = config.token;
29
+ // }
30
+ this.iframe = config.iframe;
31
+ this.postMessageClient = new PostMessageClient({
32
+ channel: 'applepay',
33
+ target: this.iframe
34
+ });
35
+ this.initialize();
36
+ }
37
+ initialize() {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ yield this.registerEventListener();
40
+ this.checkApplePayEligibility();
41
+ this.notifyApplePayEligibility();
42
+ });
43
+ }
44
+ checkApplePayEligibility() {
45
+ if (getEligibilty()) {
46
+ this.canMakePayments = true;
47
+ }
48
+ }
49
+ notifyApplePayEligibility() {
50
+ const message = {
51
+ channel,
52
+ subject: 'eligibility',
53
+ data: {
54
+ canMakePayments: this.canMakePayments
55
+ }
56
+ };
57
+ this.postMessageClient.send(message);
58
+ }
59
+ registerEventListener() {
60
+ return new Promise((resolve, reject) => {
61
+ this.postMessageClient.setEventListeners({
62
+ 'paymentrequest': (data) => __awaiter(this, void 0, void 0, function* () {
63
+ yield this.purchase(data);
64
+ })
65
+ });
66
+ resolve();
67
+ });
68
+ }
69
+ purchase(request) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const applePayPaymentRequest = this.extractApplePaymentRequestParams(request);
72
+ const payNowPaymentAttributes = this.extractPayNowPaymentAttributes(request);
73
+ this.applePaySession = yield createSession(applePayPaymentRequest);
74
+ this.applePaySession.onvalidatemerchant = (event) => __awaiter(this, void 0, void 0, function* () {
75
+ let merchantSession;
76
+ try {
77
+ merchantSession = yield payNow.getMerchantSession(event.validationURL, Object.assign(Object.assign({}, payNowPaymentAttributes), { merchant: this.username, domain_name: window.location.hostname, display_name: this.username }), `${paynowDomain}${merchantSessionPath}`, this.username, this.token);
78
+ }
79
+ catch (e) {
80
+ console.log('Unable to establish new merchant session');
81
+ return;
82
+ }
83
+ this.applePaySession.completeMerchantValidation(merchantSession);
84
+ });
85
+ this.applePaySession.onpaymentauthorized = (event) => __awaiter(this, void 0, void 0, function* () {
86
+ try {
87
+ yield payNow.authorizePayment(Object.assign(Object.assign({}, payNowPaymentAttributes), { merchant: this.username, token: event.payment.token }), `${paynowDomain}${purchaseTokenPath}`);
88
+ this.applePaySession.completePayment(window.ApplePaySession.STATUS_SUCCESS);
89
+ }
90
+ catch (e) {
91
+ this.applePaySession.completePayment(window.ApplePaySession.STATUS_FAILURE);
92
+ }
93
+ });
94
+ this.applePaySession.begin();
95
+ });
96
+ }
97
+ extractApplePaymentRequestParams(payload) {
98
+ const { countryCode, currencyCode, merchantCapabilities, supportedNetworks, total, } = payload;
99
+ return {
100
+ countryCode,
101
+ currencyCode,
102
+ merchantCapabilities,
103
+ supportedNetworks,
104
+ total,
105
+ };
106
+ }
107
+ extractPayNowPaymentAttributes(payload) {
108
+ const { paymentAttributes } = payload;
109
+ return paymentAttributes;
110
+ }
111
+ sendMessage(payload) {
112
+ this.iframe.contentWindow.postMessage(payload, this.fzPayNowDomain);
113
+ }
114
+ }
115
+ export default ApplePayManager;
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ import * as FatZebra from "../shared/types";
3
+ type FrameProps = {
4
+ handlers: FatZebra.Handlers;
5
+ config: FatZebra.PaymentConfig;
6
+ username: string;
7
+ token: string;
8
+ };
9
+ declare const ApplePayButton: ({ handlers, config, username, token }: FrameProps) => React.JSX.Element;
10
+ export default ApplePayButton;
@@ -0,0 +1,33 @@
1
+ import React, { useEffect } from "react";
2
+ import ApplePayManager from "../applepay/applepaymanager";
3
+ import useFatZebra from "./useFatZebra";
4
+ const ApplePayButton = ({ handlers, config, username, token }) => {
5
+ const ref = React.createRef();
6
+ // construct apple pay url
7
+ const { applePayUrl } = useFatZebra({
8
+ config: Object.assign(Object.assign({}, config), { options: Object.assign(Object.assign({}, config.options), { applepay: true }) }),
9
+ handlers: handlers,
10
+ });
11
+ useEffect(() => {
12
+ const iframe = ref.current;
13
+ const handleLoad = () => {
14
+ // this registers events
15
+ // fires off a message to paynow to display the apple button
16
+ // listens for click on paynow side
17
+ new ApplePayManager({
18
+ iframe: ref.current,
19
+ fzPayNowDomain: 'https://paynow.test',
20
+ username,
21
+ token
22
+ });
23
+ };
24
+ // Add event listener for load event
25
+ iframe.addEventListener('load', handleLoad);
26
+ return () => {
27
+ iframe.removeEventListener('load', handleLoad);
28
+ };
29
+ }, [ref]);
30
+ // this is the size of the button
31
+ return React.createElement("iframe", { ref: ref, src: applePayUrl, allow: "payment", style: { height: '30px', width: '100px' } });
32
+ };
33
+ export default ApplePayButton;
@@ -2,14 +2,6 @@ import { parseTemplate } from 'url-template';
2
2
  import env, { Environment } from "../shared/env";
3
3
  const generateApplePayUrl = (values, environment) => {
4
4
  const queryParts = [
5
- "tokenize_only",
6
- "css",
7
- "css_signature",
8
- "iframe",
9
- "postmessage",
10
- "hide_card_holder",
11
- "hide_button",
12
- "sca_enabled",
13
5
  "applepay"
14
6
  ];
15
7
  const environmentConfig = env[environment || Environment.sandbox];
@@ -20,14 +12,6 @@ const generateApplePayUrl = (values, environment) => {
20
12
  currency: values.currency,
21
13
  amount: values.amount,
22
14
  verification: values.hash,
23
- sca_enabled: values.sca_enabled,
24
- css: values.css,
25
- css_signature: values.css_signature,
26
- iframe: true,
27
- postmessage: true,
28
- tokenize_only: values.tokenize_only,
29
- hide_card_holder: values.hide_card_holder,
30
- hide_button: values.hide_button,
31
15
  applepay: values.applepay
32
16
  });
33
17
  return url;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "1.5.3-beta.3";
1
+ export declare const version = "1.5.4";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.5.3-beta.3';
1
+ export const version = '1.5.4';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fat-zebra/sdk",
3
- "version": "1.5.3-beta.3",
3
+ "version": "1.5.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {