@internetarchive/donation-form 0.5.11 → 0.5.12-a3
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/dist/src/braintree-manager/payment-providers/paypal/paypal-button-datasource.d.ts +11 -1
- package/dist/src/braintree-manager/payment-providers/paypal/paypal-button-datasource.js +8 -0
- package/dist/src/braintree-manager/payment-providers/paypal/paypal-button-datasource.js.map +1 -1
- package/dist/src/donation-form-controller.d.ts +8 -1
- package/dist/src/donation-form-controller.js +7 -1
- package/dist/src/donation-form-controller.js.map +1 -1
- package/dist/src/donation-form.d.ts +8 -1
- package/dist/src/donation-form.js +6 -0
- package/dist/src/donation-form.js.map +1 -1
- package/dist/src/modals/confirm-donation-modal-content.d.ts +31 -0
- package/dist/src/modals/confirm-donation-modal-content.js +169 -0
- package/dist/src/modals/confirm-donation-modal-content.js.map +1 -0
- package/dist/src/payment-flow-handlers/donation-flow-modal-manager.d.ts +16 -1
- package/dist/src/payment-flow-handlers/donation-flow-modal-manager.js +30 -0
- package/dist/src/payment-flow-handlers/donation-flow-modal-manager.js.map +1 -1
- package/dist/src/payment-flow-handlers/handlers/paypal-flow-handler.d.ts +1 -0
- package/dist/src/payment-flow-handlers/handlers/paypal-flow-handler.js +24 -0
- package/dist/src/payment-flow-handlers/handlers/paypal-flow-handler.js.map +1 -1
- package/dist/src/payment-flow-handlers/payment-flow-handlers.d.ts +16 -0
- package/dist/src/payment-flow-handlers/payment-flow-handlers.js +4 -0
- package/dist/src/payment-flow-handlers/payment-flow-handlers.js.map +1 -1
- package/dist/test/mocks/flow-handlers/mock-payment-flow-handlers.d.ts +6 -0
- package/dist/test/mocks/flow-handlers/mock-payment-flow-handlers.js +3 -0
- package/dist/test/mocks/flow-handlers/mock-payment-flow-handlers.js.map +1 -1
- package/dist/test/mocks/payment-providers/individual-providers/mock-paypal-button-datasource-delegate.d.ts +1 -0
- package/dist/test/mocks/payment-providers/individual-providers/mock-paypal-button-datasource-delegate.js +7 -0
- package/dist/test/mocks/payment-providers/individual-providers/mock-paypal-button-datasource-delegate.js.map +1 -1
- package/package.json +1 -1
- package/src/braintree-manager/payment-providers/paypal/paypal-button-datasource.ts +21 -1
- package/src/donation-form-controller.ts +11 -1
- package/src/donation-form.ts +10 -0
- package/src/modals/confirm-donation-modal-content.ts +160 -0
- package/src/payment-flow-handlers/donation-flow-modal-manager.ts +45 -0
- package/src/payment-flow-handlers/handlers/paypal-flow-handler.ts +30 -1
- package/src/payment-flow-handlers/payment-flow-handlers.ts +20 -0
- package/dist/.DS_Store +0 -0
- package/dist/src/.DS_Store +0 -0
- package/dist/src/models/donation-form-config.d.ts +0 -6
- package/dist/src/models/donation-form-config.js +0 -6
- package/dist/src/models/donation-form-config.js.map +0 -1
- package/dist/test/.DS_Store +0 -0
- package/dist/test/helpers/promisedSleep.d.ts +0 -1
- package/dist/test/helpers/promisedSleep.js +0 -4
- package/dist/test/helpers/promisedSleep.js.map +0 -1
- package/src/.DS_Store +0 -0
- package/src/@types/.DS_Store +0 -0
- package/src/form-elements/.DS_Store +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock-payment-flow-handlers.js","sourceRoot":"","sources":["../../../../test/mocks/flow-handlers/mock-payment-flow-handlers.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,oDAAoD,CAAC;AAC/F,OAAO,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,kDAAkD,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,+CAA+C,CAAC;AACrF,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC;
|
|
1
|
+
{"version":3,"file":"mock-payment-flow-handlers.js","sourceRoot":"","sources":["../../../../test/mocks/flow-handlers/mock-payment-flow-handlers.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,oDAAoD,CAAC;AAC/F,OAAO,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,kDAAkD,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,+CAA+C,CAAC;AACrF,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC;AAI7F,MAAM,OAAO,uBAAuB;IAApC;QAkBE,kBAAa,GAAG,KAAK,CAAC;QAKtB,sBAAiB,GAA8B,IAAI,yBAAyB,EAAE,CAAC;QAC/E,kBAAa,GAA0B,IAAI,qBAAqB,EAAE,CAAC;QACnE,oBAAe,GAA4B,IAAI,uBAAuB,EAAE,CAAC;QACzE,iBAAY,GAAyB,IAAI,oBAAoB,EAAE,CAAC;QAChE,qBAAgB,GAA6B,IAAI,wBAAwB,EAAE,CAAC;IAC9E,CAAC;IA3BC,eAAe,CAAC,OAOf;QACC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IACD,yBAAyB,CAAC,OAIzB;QACC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAEK,OAAO;;;YACX,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;YAC1B,MAAA,IAAI,CAAC,YAAY,0CAAE,OAAO,GAAG;;KAC9B;CAMF","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { PaymentFlowHandlersInterface } from '../../../src/payment-flow-handlers/payment-flow-handlers';\nimport { MockCreditCardFlowHandler } from './individual-handlers/mock-creditcard-flow-handler';\nimport { MockPayPalFlowHandler } from './individual-handlers/mock-paypal-flow-handler';\nimport { MockApplePayFlowHandler } from './individual-handlers/mock-applepay-flow-handler';\nimport { MockVenmoFlowHandler } from './individual-handlers/mock-venmo-flow-handler';\nimport { MockGooglePayFlowHandler } from './individual-handlers/mock-googlepay-flow-handler';\nimport { UpsellModalCTAMode } from '../../../src/modals/upsell-modal-content';\nimport { DonationType } from '@internetarchive/donation-form-data-models';\n\nexport class MockPaymentFlowHandlers implements PaymentFlowHandlersInterface {\n showUpsellModal(options: {\n oneTimeAmount: number;\n ctaMode?: UpsellModalCTAMode;\n yesSelected?: (amount: number) => void;\n noSelected?: () => void;\n amountChanged?: (amount: number) => void;\n userClosedModalCallback?: () => void;\n }): Promise<void> {\n throw new Error('Method not implemented.');\n }\n showConfirmationStepModal(options: {\n amount: number;\n donationType: DonationType;\n currencyType: string;\n }): Promise<void> {\n throw new Error('Method not implemented.');\n }\n startupCalled = false;\n async startup(): Promise<void> {\n this.startupCalled = true;\n this.venmoHandler?.startup();\n }\n creditCardHandler: MockCreditCardFlowHandler = new MockCreditCardFlowHandler();\n paypalHandler: MockPayPalFlowHandler = new MockPayPalFlowHandler();\n applePayHandler: MockApplePayFlowHandler = new MockApplePayFlowHandler();\n venmoHandler: MockVenmoFlowHandler = new MockVenmoFlowHandler();\n googlePayHandler: MockGooglePayFlowHandler = new MockGooglePayFlowHandler();\n}\n"]}
|
|
@@ -22,6 +22,7 @@ export declare class MockPayPalButtonDataSourceDelegate implements PayPalButtonD
|
|
|
22
22
|
};
|
|
23
23
|
payPalPaymentStarted(dataSource: PayPalButtonDataSourceInterface, options: object): Promise<void>;
|
|
24
24
|
payPalPaymentAuthorized(dataSource: PayPalButtonDataSourceInterface, payload: paypal.TokenizePayload): Promise<void>;
|
|
25
|
+
payPalPaymentConfirmed(dataSource: PayPalButtonDataSourceInterface, payload: paypal.TokenizePayload): Promise<void>;
|
|
25
26
|
payPalPaymentCancelled(dataSource: PayPalButtonDataSourceInterface, data: object): Promise<void>;
|
|
26
27
|
payPalPaymentError(dataSource: PayPalButtonDataSourceInterface, error: string): Promise<void>;
|
|
27
28
|
}
|
|
@@ -28,6 +28,13 @@ export class MockPayPalButtonDataSourceDelegate {
|
|
|
28
28
|
this.paymentAuthorizedResults.payload = payload;
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
+
payPalPaymentConfirmed(dataSource, payload) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
this.paymentAuthorizedResults.called = true;
|
|
34
|
+
this.paymentAuthorizedResults.datasource = dataSource;
|
|
35
|
+
this.paymentAuthorizedResults.payload = payload;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
31
38
|
payPalPaymentCancelled(dataSource, data) {
|
|
32
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
40
|
this.paymentCancelledResults.called = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock-paypal-button-datasource-delegate.js","sourceRoot":"","sources":["../../../../../test/mocks/payment-providers/individual-providers/mock-paypal-button-datasource-delegate.ts"],"names":[],"mappings":";AAKA,MAAM,OAAO,kCAAkC;IAA/C;QACE,0BAAqB,GAIjB;YACF,MAAM,EAAE,KAAK;SACd,CAAC;QAEF,6BAAwB,GAIpB;YACF,MAAM,EAAE,KAAK;SACd,CAAC;QAEF,4BAAuB,GAInB;YACF,MAAM,EAAE,KAAK;SACd,CAAC;QAEF,wBAAmB,GAIf;YACF,MAAM,EAAE,KAAK;SACd,CAAC;
|
|
1
|
+
{"version":3,"file":"mock-paypal-button-datasource-delegate.js","sourceRoot":"","sources":["../../../../../test/mocks/payment-providers/individual-providers/mock-paypal-button-datasource-delegate.ts"],"names":[],"mappings":";AAKA,MAAM,OAAO,kCAAkC;IAA/C;QACE,0BAAqB,GAIjB;YACF,MAAM,EAAE,KAAK;SACd,CAAC;QAEF,6BAAwB,GAIpB;YACF,MAAM,EAAE,KAAK;SACd,CAAC;QAEF,4BAAuB,GAInB;YACF,MAAM,EAAE,KAAK;SACd,CAAC;QAEF,wBAAmB,GAIf;YACF,MAAM,EAAE,KAAK;SACd,CAAC;IA8CJ,CAAC;IA5CO,oBAAoB,CACxB,UAA2C,EAC3C,OAAe;;YAEf,IAAI,CAAC,qBAAqB,CAAC,MAAM,GAAG,IAAI,CAAC;YACzC,IAAI,CAAC,qBAAqB,CAAC,UAAU,GAAG,UAAU,CAAC;YACnD,IAAI,CAAC,qBAAqB,CAAC,OAAO,GAAG,OAAO,CAAC;QAC/C,CAAC;KAAA;IAEK,uBAAuB,CAC3B,UAA2C,EAC3C,OAA+B;;YAE/B,IAAI,CAAC,wBAAwB,CAAC,MAAM,GAAG,IAAI,CAAC;YAC5C,IAAI,CAAC,wBAAwB,CAAC,UAAU,GAAG,UAAU,CAAC;YACtD,IAAI,CAAC,wBAAwB,CAAC,OAAO,GAAG,OAAO,CAAC;QAClD,CAAC;KAAA;IAEK,sBAAsB,CAC1B,UAA2C,EAC3C,OAA+B;;YAE/B,IAAI,CAAC,wBAAwB,CAAC,MAAM,GAAG,IAAI,CAAC;YAC5C,IAAI,CAAC,wBAAwB,CAAC,UAAU,GAAG,UAAU,CAAC;YACtD,IAAI,CAAC,wBAAwB,CAAC,OAAO,GAAG,OAAO,CAAC;QAClD,CAAC;KAAA;IAEK,sBAAsB,CAC1B,UAA2C,EAC3C,IAAY;;YAEZ,IAAI,CAAC,uBAAuB,CAAC,MAAM,GAAG,IAAI,CAAC;YAC3C,IAAI,CAAC,uBAAuB,CAAC,UAAU,GAAG,UAAU,CAAC;YACrD,IAAI,CAAC,uBAAuB,CAAC,IAAI,GAAG,IAAI,CAAC;QAC3C,CAAC;KAAA;IAEK,kBAAkB,CACtB,UAA2C,EAC3C,KAAa;;YAEb,IAAI,CAAC,mBAAmB,CAAC,MAAM,GAAG,IAAI,CAAC;YACvC,IAAI,CAAC,mBAAmB,CAAC,UAAU,GAAG,UAAU,CAAC;YACjD,IAAI,CAAC,mBAAmB,CAAC,KAAK,GAAG,KAAK,CAAC;QACzC,CAAC;KAAA;CACF","sourcesContent":["import {\n PayPalButtonDataSourceDelegate,\n PayPalButtonDataSourceInterface,\n} from '../../../../src/braintree-manager/payment-providers/paypal/paypal-button-datasource';\n\nexport class MockPayPalButtonDataSourceDelegate implements PayPalButtonDataSourceDelegate {\n paymentStartedResults: {\n called: boolean;\n datasource?: PayPalButtonDataSourceInterface;\n options?: object;\n } = {\n called: false,\n };\n\n paymentAuthorizedResults: {\n called: boolean;\n datasource?: PayPalButtonDataSourceInterface;\n payload?: paypal.TokenizePayload;\n } = {\n called: false,\n };\n\n paymentCancelledResults: {\n called: boolean;\n datasource?: PayPalButtonDataSourceInterface;\n data?: object;\n } = {\n called: false,\n };\n\n paymentErrorResults: {\n called: boolean;\n datasource?: PayPalButtonDataSourceInterface;\n error?: string;\n } = {\n called: false,\n };\n\n async payPalPaymentStarted(\n dataSource: PayPalButtonDataSourceInterface,\n options: object,\n ): Promise<void> {\n this.paymentStartedResults.called = true;\n this.paymentStartedResults.datasource = dataSource;\n this.paymentStartedResults.options = options;\n }\n\n async payPalPaymentAuthorized(\n dataSource: PayPalButtonDataSourceInterface,\n payload: paypal.TokenizePayload,\n ): Promise<void> {\n this.paymentAuthorizedResults.called = true;\n this.paymentAuthorizedResults.datasource = dataSource;\n this.paymentAuthorizedResults.payload = payload;\n }\n\n async payPalPaymentConfirmed(\n dataSource: PayPalButtonDataSourceInterface,\n payload: paypal.TokenizePayload,\n ): Promise<void> {\n this.paymentAuthorizedResults.called = true;\n this.paymentAuthorizedResults.datasource = dataSource;\n this.paymentAuthorizedResults.payload = payload;\n }\n\n async payPalPaymentCancelled(\n dataSource: PayPalButtonDataSourceInterface,\n data: object,\n ): Promise<void> {\n this.paymentCancelledResults.called = true;\n this.paymentCancelledResults.datasource = dataSource;\n this.paymentCancelledResults.data = data;\n }\n\n async payPalPaymentError(\n dataSource: PayPalButtonDataSourceInterface,\n error: string,\n ): Promise<void> {\n this.paymentErrorResults.called = true;\n this.paymentErrorResults.datasource = dataSource;\n this.paymentErrorResults.error = error;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -92,7 +92,7 @@ export interface PayPalButtonDataSourceDelegate {
|
|
|
92
92
|
payPalPaymentStarted(dataSource: PayPalButtonDataSourceInterface, options: object): Promise<void>;
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
* Payment has been authorized
|
|
95
|
+
* Payment has been authorized by patron and submits to PayPal
|
|
96
96
|
*
|
|
97
97
|
* @param {PayPalButtonDataSourceInterface} dataSource
|
|
98
98
|
* @param {paypal.TokenizePayload} payload
|
|
@@ -104,6 +104,19 @@ export interface PayPalButtonDataSourceDelegate {
|
|
|
104
104
|
payload: paypal.TokenizePayload,
|
|
105
105
|
): Promise<void>;
|
|
106
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Payment has been authorized
|
|
109
|
+
*
|
|
110
|
+
* @param {PayPalButtonDataSourceInterface} dataSource
|
|
111
|
+
* @param {paypal.TokenizePayload} payload
|
|
112
|
+
* @returns {Promise<void>}
|
|
113
|
+
* @memberof PayPalButtonDataSourceDelegate
|
|
114
|
+
*/
|
|
115
|
+
payPalPaymentConfirmed(
|
|
116
|
+
dataSource: PayPalButtonDataSourceInterface,
|
|
117
|
+
payload: paypal.TokenizePayload,
|
|
118
|
+
): Promise<void>;
|
|
119
|
+
|
|
107
120
|
/**
|
|
108
121
|
* Payment has been cancelled
|
|
109
122
|
*
|
|
@@ -185,6 +198,13 @@ export class PayPalButtonDataSource implements PayPalButtonDataSourceInterface {
|
|
|
185
198
|
return payload;
|
|
186
199
|
}
|
|
187
200
|
|
|
201
|
+
async onConfirm(data: paypal.AuthorizationData): Promise<paypal.TokenizePayload> {
|
|
202
|
+
const payload: paypal.TokenizePayload = await this.paypalInstance.tokenizePayment(data);
|
|
203
|
+
this.delegate?.payPalPaymentConfirmed(this, payload);
|
|
204
|
+
|
|
205
|
+
return payload;
|
|
206
|
+
}
|
|
207
|
+
|
|
188
208
|
/** @inheritdoc */
|
|
189
209
|
onCancel(data: object): void {
|
|
190
210
|
this.delegate?.payPalPaymentCancelled(this, data);
|
|
@@ -164,6 +164,16 @@ export class DonationFormController extends LitElement {
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
async showConfirmationStepDev(options: {
|
|
168
|
+
donationType: DonationType;
|
|
169
|
+
amount: number;
|
|
170
|
+
currencyType: string;
|
|
171
|
+
cancelDonationCB: Function;
|
|
172
|
+
confirmDonationCB: Function;
|
|
173
|
+
}): Promise<void> {
|
|
174
|
+
this.donationForm.showConfirmationModalDev(options);
|
|
175
|
+
}
|
|
176
|
+
|
|
167
177
|
async showUpsellModalDev(options: {
|
|
168
178
|
oneTimeAmount: number;
|
|
169
179
|
ctaMode?: UpsellModalCTAMode;
|
|
@@ -319,7 +329,7 @@ export class DonationFormController extends LitElement {
|
|
|
319
329
|
this.donationForm.paymentFlowHandlers = this.paymentFlowHandlers;
|
|
320
330
|
|
|
321
331
|
this.braintreeManager.startup();
|
|
322
|
-
this.paymentFlowHandlers
|
|
332
|
+
this.paymentFlowHandlers?.startup();
|
|
323
333
|
this.recaptchaManager.setup(this.recaptchaElement, 1, 'light', 'image');
|
|
324
334
|
}
|
|
325
335
|
|
package/src/donation-form.ts
CHANGED
|
@@ -121,6 +121,16 @@ export class DonationForm extends LitElement {
|
|
|
121
121
|
`;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
async showConfirmationModalDev(options: {
|
|
125
|
+
donationType: DonationType;
|
|
126
|
+
amount: number;
|
|
127
|
+
currencyType: string;
|
|
128
|
+
cancelDonationCB: Function;
|
|
129
|
+
confirmDonationCB: Function;
|
|
130
|
+
}): Promise<void> {
|
|
131
|
+
this.paymentFlowHandlers?.showConfirmationStepModal(options);
|
|
132
|
+
}
|
|
133
|
+
|
|
124
134
|
/**
|
|
125
135
|
* This is a developer convenience method that allows us to show the upsell modal without going
|
|
126
136
|
* through the purchasing flow. If it's showing the PayPal button, it will trigger
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
2
|
+
import { LitElement, html, TemplateResult, css, CSSResultGroup, nothing } from 'lit';
|
|
3
|
+
import { customElement, property } from 'lit/decorators.js';
|
|
4
|
+
import { DonationType } from '@internetarchive/donation-form-data-models';
|
|
5
|
+
import currency from 'currency.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* This is the content that we show in the upsell modal.
|
|
9
|
+
*
|
|
10
|
+
* It has an amount input, "Yes" and "No Thanks" options and a switch to optionally
|
|
11
|
+
* show the PayPal upsell button.
|
|
12
|
+
*
|
|
13
|
+
* @export
|
|
14
|
+
* @class ConfirmDonationContent
|
|
15
|
+
* @extends {LitElement}
|
|
16
|
+
*/
|
|
17
|
+
@customElement('confirm-donation-modal')
|
|
18
|
+
export class ConfirmDonationContent extends LitElement {
|
|
19
|
+
@property({ type: Number }) amount = 5;
|
|
20
|
+
|
|
21
|
+
@property({ type: String }) currencyType = '$';
|
|
22
|
+
|
|
23
|
+
@property({ type: String }) donationType: DonationType = DonationType.OneTime;
|
|
24
|
+
|
|
25
|
+
@property({ type: Function }) confirmDonation: Function = (): void => {};
|
|
26
|
+
|
|
27
|
+
@property({ type: Function }) cancelDonation: Function= (): void => {};
|
|
28
|
+
|
|
29
|
+
get confirmationText(): TemplateResult {
|
|
30
|
+
const amount = currency(this.amount, { symbol: this.currencySymbol }).format();
|
|
31
|
+
return html`
|
|
32
|
+
<p>You are about to make a <b>${this.donationType}</b> donation of <b>${amount} ${this.currencyType}</b> to the Internet Archive.</p>
|
|
33
|
+
`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get confirmUpsellText(): TemplateResult {
|
|
37
|
+
const amount = currency(this.amount, { symbol: this.currencySymbol }).format();
|
|
38
|
+
return html`<p>You are about to begin making <b>monthly</b> donations of <b>${amount} ${this.currencyType}</b> to the Internet Archive. (Your first recurring contribution will be next month.)</p>`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
confirm(): void {
|
|
42
|
+
this?.confirmDonation();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
cancel(): void {
|
|
46
|
+
this?.cancelDonation();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get confirmCTA(): string {
|
|
50
|
+
return this.donationType === DonationType.Upsell ? 'Start monthly donation' : 'Complete donation';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** @inheritdoc */
|
|
54
|
+
render(): TemplateResult {
|
|
55
|
+
return html`
|
|
56
|
+
${this.donationType === DonationType.Upsell ? this.confirmUpsellText : this.confirmationText}
|
|
57
|
+
|
|
58
|
+
<div class="cta-group">
|
|
59
|
+
<button id="confirm" @click=${(): void => this.confirm()}>${this.confirmCTA}</button>
|
|
60
|
+
<button id="cancel" @click=${(): void => this.cancel()}>Cancel</button>
|
|
61
|
+
</div>
|
|
62
|
+
`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static get styles(): CSSResultGroup {
|
|
66
|
+
const ctaButtonColor = css`var(--upsellCTAButtonColor, #194880)`;
|
|
67
|
+
const ctaButtonDisabledColor = css`var(--upsellCTAButtonDisabledColor, rgba(109,148,201,0.5))`;
|
|
68
|
+
|
|
69
|
+
return css`
|
|
70
|
+
:host {
|
|
71
|
+
display: block;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
button {
|
|
75
|
+
outline: none;
|
|
76
|
+
cursor: pointer;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
button#confirm {
|
|
80
|
+
font-size: 2rem;
|
|
81
|
+
display: block;
|
|
82
|
+
width: 100%;
|
|
83
|
+
margin-top: 0.5rem;
|
|
84
|
+
padding: 1rem 2rem;
|
|
85
|
+
background-color: ${ctaButtonColor};
|
|
86
|
+
color: #fff;
|
|
87
|
+
border-radius: 5px;
|
|
88
|
+
border: 0;
|
|
89
|
+
font-weight: bold;
|
|
90
|
+
line-height: normal;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
button#cancel {
|
|
94
|
+
margin-top: 1rem;
|
|
95
|
+
border: 0;
|
|
96
|
+
text-decoration: underline;
|
|
97
|
+
background-color: transparent;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
button:disabled {
|
|
101
|
+
background-color: ${ctaButtonDisabledColor};
|
|
102
|
+
cursor: not-allowed;
|
|
103
|
+
}
|
|
104
|
+
}`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* https://developer.paypal.com/docs/reports/reference/paypal-supported-currencies/
|
|
109
|
+
*/
|
|
110
|
+
get currencySymbol(): string {
|
|
111
|
+
switch(this.currencyType) {
|
|
112
|
+
case 'AUD':
|
|
113
|
+
return 'AU$';
|
|
114
|
+
case 'BRL':
|
|
115
|
+
return 'R$';
|
|
116
|
+
case 'CAD':
|
|
117
|
+
return 'CA$';
|
|
118
|
+
case 'CHF':
|
|
119
|
+
return 'Fr';
|
|
120
|
+
case 'CNY':
|
|
121
|
+
return '¥';
|
|
122
|
+
case 'CZK':
|
|
123
|
+
return 'Kč';
|
|
124
|
+
case 'DKK':
|
|
125
|
+
return 'Kr';
|
|
126
|
+
case 'EUR':
|
|
127
|
+
return '€';
|
|
128
|
+
case 'GBP':
|
|
129
|
+
return '£';
|
|
130
|
+
case 'HKD':
|
|
131
|
+
return 'HK$';
|
|
132
|
+
case 'HUF':
|
|
133
|
+
return 'Ft';
|
|
134
|
+
case 'ILS':
|
|
135
|
+
return '₪';
|
|
136
|
+
case 'JPY':
|
|
137
|
+
return '¥';
|
|
138
|
+
case 'MXN':
|
|
139
|
+
return 'MX$';
|
|
140
|
+
case 'MYR':
|
|
141
|
+
return 'RM';
|
|
142
|
+
case 'NOK':
|
|
143
|
+
return 'kr';
|
|
144
|
+
case 'PLN':
|
|
145
|
+
return 'zł';
|
|
146
|
+
case 'RUB':
|
|
147
|
+
return '₽';
|
|
148
|
+
case 'SEK':
|
|
149
|
+
return 'kr';
|
|
150
|
+
case 'SGD':
|
|
151
|
+
return 'S$';
|
|
152
|
+
case 'THB':
|
|
153
|
+
return '฿';
|
|
154
|
+
case 'TYD':
|
|
155
|
+
return 'NT$';
|
|
156
|
+
default:
|
|
157
|
+
return '$'; // $ as default USD, NZD
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { html } from 'lit';
|
|
2
2
|
import { ModalConfig, ModalManagerInterface } from '@internetarchive/modal-manager';
|
|
3
3
|
import { UpsellModalCTAMode } from '../modals/upsell-modal-content';
|
|
4
|
+
import '../modals/confirm-donation-modal-content';
|
|
4
5
|
import { BraintreeManagerInterface } from '../braintree-manager/braintree-interfaces';
|
|
5
6
|
import {
|
|
6
7
|
SuccessResponse,
|
|
@@ -32,6 +33,13 @@ enum ModalHeaderColor {
|
|
|
32
33
|
* @interface DonationFlowModalManagerInterface
|
|
33
34
|
*/
|
|
34
35
|
export interface DonationFlowModalManagerInterface {
|
|
36
|
+
showConfirmationStepModal(options: {
|
|
37
|
+
amount: number;
|
|
38
|
+
donationType: DonationType;
|
|
39
|
+
currencyType: string;
|
|
40
|
+
confirmDonationCB: Function;
|
|
41
|
+
cancelDonationCB: Function;
|
|
42
|
+
}): Promise<void>;
|
|
35
43
|
/**
|
|
36
44
|
* Close the modal
|
|
37
45
|
*
|
|
@@ -212,6 +220,43 @@ export class DonationFlowModalManager implements DonationFlowModalManagerInterfa
|
|
|
212
220
|
});
|
|
213
221
|
}
|
|
214
222
|
|
|
223
|
+
showConfirmationStepModal(options: {
|
|
224
|
+
amount: number;
|
|
225
|
+
donationType: DonationType;
|
|
226
|
+
currencyType: string;
|
|
227
|
+
confirmDonationCB: Function;
|
|
228
|
+
cancelDonationCB: Function;
|
|
229
|
+
}): Promise<void> {
|
|
230
|
+
const confirmDonation = (): void => {
|
|
231
|
+
options?.confirmDonationCB();
|
|
232
|
+
};
|
|
233
|
+
const cancelDonation = (): void => {
|
|
234
|
+
options?.cancelDonationCB();
|
|
235
|
+
};
|
|
236
|
+
const modalTitle = options.donationType === DonationType.Upsell
|
|
237
|
+
? 'Confirm monthly donation'
|
|
238
|
+
: 'Complete donation';
|
|
239
|
+
|
|
240
|
+
const modalConfig = new ModalConfig({
|
|
241
|
+
closeOnBackdropClick: false,
|
|
242
|
+
headerColor: ModalHeaderColor.Green,
|
|
243
|
+
title: html`${modalTitle}`,
|
|
244
|
+
message: html`
|
|
245
|
+
<confirm-donation-modal
|
|
246
|
+
.amount="${options.amount}"
|
|
247
|
+
.currencyType="${options.currencyType}"
|
|
248
|
+
.donationType="${options.donationType}"
|
|
249
|
+
.confirmDonation=${confirmDonation}
|
|
250
|
+
.cancelDonation=${cancelDonation}
|
|
251
|
+
></confirm-donation-modal>
|
|
252
|
+
`,
|
|
253
|
+
});
|
|
254
|
+
return this.modalManager.showModal({
|
|
255
|
+
config: modalConfig,
|
|
256
|
+
userClosedModalCallback: cancelDonation
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
215
260
|
/** @inheritdoc */
|
|
216
261
|
showUpsellModal(options: {
|
|
217
262
|
oneTimeAmount: number;
|
|
@@ -112,10 +112,39 @@ export class PayPalFlowHandler
|
|
|
112
112
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
113
113
|
options: object,
|
|
114
114
|
): Promise<void> {
|
|
115
|
+
console.log('payPalPaymentStarted *******', { dataSource, options });
|
|
115
116
|
this.emitter.emit('payPalPaymentStarted', dataSource, options);
|
|
116
117
|
}
|
|
117
118
|
|
|
118
|
-
async payPalPaymentAuthorized(
|
|
119
|
+
async payPalPaymentAuthorized(dataSource: PayPalButtonDataSourceInterface,
|
|
120
|
+
payload: paypal.TokenizePayload
|
|
121
|
+
): Promise<void> {
|
|
122
|
+
|
|
123
|
+
// we got dataSource & payload
|
|
124
|
+
// we need to send it to `payPalPaymentConfirmed`
|
|
125
|
+
// after patron confirms the payment
|
|
126
|
+
console.log('payPalPaymentAuthorized *******', { dataSource, payload });
|
|
127
|
+
|
|
128
|
+
const { donationType, total } = dataSource.donationInfo;
|
|
129
|
+
this.donationFlowModalManager.showConfirmationStepModal({
|
|
130
|
+
donationType,
|
|
131
|
+
amount: total,
|
|
132
|
+
currencyType: 'USD', // defaults to USD for now
|
|
133
|
+
confirmDonationCB: () => {
|
|
134
|
+
this.payPalPaymentConfirmed(dataSource, payload);
|
|
135
|
+
},
|
|
136
|
+
cancelDonationCB: () => {
|
|
137
|
+
this.donationFlowModalManager.closeModal();
|
|
138
|
+
this.payPalPaymentCancelled(dataSource, {});
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// cancel payment on modal X
|
|
143
|
+
// cancel payment on cancel
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async payPalPaymentConfirmed(
|
|
119
148
|
dataSource: PayPalButtonDataSourceInterface,
|
|
120
149
|
payload: paypal.TokenizePayload,
|
|
121
150
|
): Promise<void> {
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
GooglePayFlowHandler,
|
|
22
22
|
} from './handlers/googlepay-flow-handler';
|
|
23
23
|
import { UpsellModalCTAMode } from '../modals/upsell-modal-content';
|
|
24
|
+
import { DonationType } from '@internetarchive/donation-form-data-models';
|
|
24
25
|
|
|
25
26
|
export interface PaymentFlowHandlersInterface {
|
|
26
27
|
startup(): Promise<void>;
|
|
@@ -46,6 +47,14 @@ export interface PaymentFlowHandlersInterface {
|
|
|
46
47
|
userClosedModalCallback?: () => void;
|
|
47
48
|
}): Promise<void>;
|
|
48
49
|
|
|
50
|
+
showConfirmationStepModal(options: {
|
|
51
|
+
amount: number;
|
|
52
|
+
donationType: DonationType;
|
|
53
|
+
currencyType: string;
|
|
54
|
+
confirmDonationCB: Function;
|
|
55
|
+
cancelDonationCB: Function;
|
|
56
|
+
}): Promise<void>;
|
|
57
|
+
|
|
49
58
|
creditCardHandler: CreditCardFlowHandlerInterface | undefined;
|
|
50
59
|
paypalHandler: PayPalFlowHandlerInterface | undefined;
|
|
51
60
|
applePayHandler: ApplePayFlowHandlerInterface | undefined;
|
|
@@ -90,6 +99,17 @@ export class PaymentFlowHandlers implements PaymentFlowHandlersInterface {
|
|
|
90
99
|
return this.donationFlowModalManager.showUpsellModal(options);
|
|
91
100
|
}
|
|
92
101
|
|
|
102
|
+
/** @inheritdoc */
|
|
103
|
+
showConfirmationStepModal(options: {
|
|
104
|
+
amount: number;
|
|
105
|
+
donationType: DonationType;
|
|
106
|
+
currencyType: string;
|
|
107
|
+
confirmDonationCB: Function;
|
|
108
|
+
cancelDonationCB: Function;
|
|
109
|
+
}): Promise<void> {
|
|
110
|
+
return this.donationFlowModalManager.showConfirmationStepModal(options);
|
|
111
|
+
}
|
|
112
|
+
|
|
93
113
|
get creditCardHandler(): CreditCardFlowHandlerInterface | undefined {
|
|
94
114
|
if (this.creditCardHandlerCache) {
|
|
95
115
|
return this.creditCardHandlerCache;
|
package/dist/.DS_Store
DELETED
|
Binary file
|
package/dist/src/.DS_Store
DELETED
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"donation-form-config.js","sourceRoot":"","sources":["../../../src/models/donation-form-config.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,kBAAkB;IAG7B,YAAY,OAA8C;QACxD,IAAI,CAAC,wBAAwB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IACnE,CAAC;CACF","sourcesContent":["export class DonationFormConfig {\n showCreditCardButtonText: boolean;\n\n constructor(options: { showCreditCardButtonText: boolean }) {\n this.showCreditCardButtonText = options.showCreditCardButtonText;\n }\n}\n"]}
|
package/dist/test/.DS_Store
DELETED
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function promisedSleep(ms: number): Promise<void>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"promisedSleep.js","sourceRoot":"","sources":["../../../test/helpers/promisedSleep.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,aAAa,CAAC,EAAU;IACtC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AACzD,CAAC","sourcesContent":["export function promisedSleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n"]}
|
package/src/.DS_Store
DELETED
|
Binary file
|
package/src/@types/.DS_Store
DELETED
|
Binary file
|
|
Binary file
|