@internetarchive/donation-form 0.5.10 → 0.5.11

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.
@@ -15,6 +15,7 @@ export class PayPalButtonDataSource {
15
15
  const flow = donationType === DonationType.OneTime ? 'checkout' : 'vault';
16
16
  const options = {
17
17
  flow: flow,
18
+ intent: 'capture',
18
19
  };
19
20
  options.enableShippingAddress = true;
20
21
  if (flow === 'checkout') {
@@ -1 +1 @@
1
- {"version":3,"file":"paypal-button-datasource.js","sourceRoot":"","sources":["../../../../../src/braintree-manager/payment-providers/paypal/paypal-button-datasource.ts"],"names":[],"mappings":";AAAA,OAAO,EAAuB,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAE/F,OAAO,QAAQ,MAAM,aAAa,CAAC;AA6HnC,kBAAkB;AAClB,MAAM,OAAO,sBAAsB;IAgBjC,YAAY,OAGX;QACC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAC/C,CAAC;IAED,kBAAkB;IACZ,OAAO;;;YACX,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC;YACpD,MAAM,IAAI,GAAG,YAAY,KAAK,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC;YAE1E,MAAM,OAAO,GAAiD;gBAC5D,IAAI,EAAE,IAAuB;aAC9B,CAAC;YACF,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;YAErC,IAAI,IAAI,KAAK,UAAU,EAAE;gBACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;gBACzC,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC;aAC1B;iBAAM;gBACL,OAAO,CAAC,2BAA2B,GAAG,uBAAuB,QAAQ,CACnE,IAAI,CAAC,YAAY,CAAC,KAAK,EACvB,EAAE,MAAM,EAAE,GAAG,EAAE,CAChB,CAAC,MAAM,EAAE,UAAU,CAAC;aACtB;YAED,MAAA,IAAI,CAAC,QAAQ,0CAAE,oBAAoB,CAAC,IAAI,EAAE,OAAO,EAAE;YAEnD,OAAO,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;;KACnD;IAED,kBAAkB;IACZ,WAAW,CAAC,IAA8B;;;YAC9C,MAAM,OAAO,GAA2B,MAAM,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YAExF,MAAA,IAAI,CAAC,QAAQ,0CAAE,uBAAuB,CAAC,IAAI,EAAE,OAAO,EAAE;YAEtD,OAAO,OAAO,CAAC;;KAChB;IAED,kBAAkB;IAClB,QAAQ,CAAC,IAAY;;QACnB,MAAA,IAAI,CAAC,QAAQ,0CAAE,sBAAsB,CAAC,IAAI,EAAE,IAAI,EAAE;IACpD,CAAC;IAED,kBAAkB;IAClB,OAAO,CAAC,KAAa;;QACnB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;QACrC,MAAA,IAAI,CAAC,QAAQ,0CAAE,kBAAkB,CAAC,IAAI,EAAE,KAAK,EAAE;IACjD,CAAC;CACF","sourcesContent":["import { DonationPaymentInfo, DonationType } from '@internetarchive/donation-form-data-models';\n\nimport currency from 'currency.js';\n\n/**\n * PayPayButtonDataSource is responsible for communicating with the PayPal button.\n *\n * The PayPal button cannot live in the ShadowDOM so we have to instantiate it at the\n * top of the DOM and it lives in the global sphere. This makes it difficult to communicate\n * with it directly. The PayPalButtonDataSource provides an object that we can pass around\n * that hooks into all of the PayPal button's callbacks and provides callbacks to its\n * delegate that is interested in the various events.\n *\n * @export\n * @interface PayPalButtonDataSourceInterface\n */\nexport interface PayPalButtonDataSourceInterface {\n /**\n * The delegate to inform about button events\n *\n * @type {PayPalButtonDataSourceDelegate}\n * @memberof PayPalButtonDataSourceInterface\n */\n delegate?: PayPalButtonDataSourceDelegate;\n\n /**\n * The Donation Info associated with this button.\n *\n * Since the user initiates the checkout flow from the button itself (not programatically by us),\n * we need to have up-to-date donation information so whenever the user updates donation info\n * from the form, we update this.\n *\n * @type {DonationPaymentInfo}\n * @memberof PayPalButtonDataSourceInterface\n */\n donationInfo: DonationPaymentInfo;\n\n /**\n * The payment has been started by the user (they clicked the PayPal button)\n *\n * @returns {Promise<string>}\n * @memberof PayPalButtonDataSourceInterface\n */\n payment(): Promise<string>;\n\n /**\n * The user has authorized the donation\n *\n * @param {paypal.AuthorizationData} data\n * @param {object} actions\n * @returns {(Promise<paypal.TokenizePayload | undefined>)}\n * @memberof PayPalButtonDataSourceInterface\n */\n onAuthorize(\n data: paypal.AuthorizationData,\n actions: object,\n ): Promise<paypal.TokenizePayload | undefined>;\n\n /**\n * The user cancelled the donation\n *\n * @param {paypal.CancellationData} data\n * @memberof PayPalButtonDataSourceInterface\n */\n onCancel(data: paypal.CancellationData): void;\n\n /**\n * An error occurred\n *\n * @param {string} error\n * @memberof PayPalButtonDataSourceInterface\n */\n onError(error: string): void;\n}\n\n/**\n * The PayPalButtonDataSourceDelegate is an interface for any object interested\n * in events emitted by the paypal button.\n *\n * @export\n * @interface PayPalButtonDataSourceDelegate\n */\nexport interface PayPalButtonDataSourceDelegate {\n /**\n * Payment has been started\n *\n * @param {PayPalButtonDataSourceInterface} dataSource\n * @param {object} options\n * @returns {Promise<void>}\n * @memberof PayPalButtonDataSourceDelegate\n */\n payPalPaymentStarted(dataSource: PayPalButtonDataSourceInterface, options: object): Promise<void>;\n\n /**\n * Payment has been authorized\n *\n * @param {PayPalButtonDataSourceInterface} dataSource\n * @param {paypal.TokenizePayload} payload\n * @returns {Promise<void>}\n * @memberof PayPalButtonDataSourceDelegate\n */\n payPalPaymentAuthorized(\n dataSource: PayPalButtonDataSourceInterface,\n payload: paypal.TokenizePayload,\n ): Promise<void>;\n\n /**\n * Payment has been cancelled\n *\n * @param {PayPalButtonDataSourceInterface} dataSource\n * @param {object} data\n * @returns {Promise<void>}\n * @memberof PayPalButtonDataSourceDelegate\n */\n payPalPaymentCancelled(dataSource: PayPalButtonDataSourceInterface, data: object): Promise<void>;\n\n /**\n * There was a payment error\n *\n * @param {PayPalButtonDataSourceInterface} dataSource\n * @param {string} error\n * @returns {Promise<void>}\n * @memberof PayPalButtonDataSourceDelegate\n */\n payPalPaymentError(dataSource: PayPalButtonDataSourceInterface, error: string): Promise<void>;\n}\n\n/** @inheritdoc */\nexport class PayPalButtonDataSource implements PayPalButtonDataSourceInterface {\n /** @inheritdoc */\n delegate?: PayPalButtonDataSourceDelegate;\n\n /** @inheritdoc */\n donationInfo: DonationPaymentInfo;\n\n /**\n * The PayPal instance\n *\n * @private\n * @type {braintree.PayPalCheckout}\n * @memberof PayPalButtonDataSource\n */\n private paypalInstance: braintree.PayPalCheckout;\n\n constructor(options: {\n donationInfo: DonationPaymentInfo;\n paypalInstance: braintree.PayPalCheckout;\n }) {\n this.donationInfo = options.donationInfo;\n this.paypalInstance = options.paypalInstance;\n }\n\n /** @inheritdoc */\n async payment(): Promise<string> {\n const donationType = this.donationInfo.donationType;\n const flow = donationType === DonationType.OneTime ? 'checkout' : 'vault';\n\n const options: braintree.PayPalCheckoutCreatePaymentOptions = {\n flow: flow as paypal.FlowType,\n };\n options.enableShippingAddress = true;\n\n if (flow === 'checkout') {\n options.amount = this.donationInfo.total;\n options.currency = 'USD';\n } else {\n options.billingAgreementDescription = `Subscribe to donate ${currency(\n this.donationInfo.total,\n { symbol: '$' },\n ).format()} monthly`;\n }\n\n this.delegate?.payPalPaymentStarted(this, options);\n\n return this.paypalInstance.createPayment(options);\n }\n\n /** @inheritdoc */\n async onAuthorize(data: paypal.AuthorizationData): Promise<paypal.TokenizePayload> {\n const payload: paypal.TokenizePayload = await this.paypalInstance.tokenizePayment(data);\n\n this.delegate?.payPalPaymentAuthorized(this, payload);\n\n return payload;\n }\n\n /** @inheritdoc */\n onCancel(data: object): void {\n this.delegate?.payPalPaymentCancelled(this, data);\n }\n\n /** @inheritdoc */\n onError(error: string): void {\n console.error('PayPal error', error);\n this.delegate?.payPalPaymentError(this, error);\n }\n}\n"]}
1
+ {"version":3,"file":"paypal-button-datasource.js","sourceRoot":"","sources":["../../../../../src/braintree-manager/payment-providers/paypal/paypal-button-datasource.ts"],"names":[],"mappings":";AAAA,OAAO,EAAuB,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAE/F,OAAO,QAAQ,MAAM,aAAa,CAAC;AA6HnC,kBAAkB;AAClB,MAAM,OAAO,sBAAsB;IAgBjC,YAAY,OAGX;QACC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAC/C,CAAC;IAED,kBAAkB;IACZ,OAAO;;;YACX,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC;YACpD,MAAM,IAAI,GAAG,YAAY,KAAK,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC;YAE1E,MAAM,OAAO,GAAiD;gBAC5D,IAAI,EAAE,IAAuB;gBAC7B,MAAM,EAAE,SAAS;aAClB,CAAC;YACF,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;YAErC,IAAI,IAAI,KAAK,UAAU,EAAE;gBACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;gBACzC,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC;aAC1B;iBAAM;gBACL,OAAO,CAAC,2BAA2B,GAAG,uBAAuB,QAAQ,CACnE,IAAI,CAAC,YAAY,CAAC,KAAK,EACvB,EAAE,MAAM,EAAE,GAAG,EAAE,CAChB,CAAC,MAAM,EAAE,UAAU,CAAC;aACtB;YAED,MAAA,IAAI,CAAC,QAAQ,0CAAE,oBAAoB,CAAC,IAAI,EAAE,OAAO,EAAE;YAEnD,OAAO,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;;KACnD;IAED,kBAAkB;IACZ,WAAW,CAAC,IAA8B;;;YAC9C,MAAM,OAAO,GAA2B,MAAM,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YAExF,MAAA,IAAI,CAAC,QAAQ,0CAAE,uBAAuB,CAAC,IAAI,EAAE,OAAO,EAAE;YAEtD,OAAO,OAAO,CAAC;;KAChB;IAED,kBAAkB;IAClB,QAAQ,CAAC,IAAY;;QACnB,MAAA,IAAI,CAAC,QAAQ,0CAAE,sBAAsB,CAAC,IAAI,EAAE,IAAI,EAAE;IACpD,CAAC;IAED,kBAAkB;IAClB,OAAO,CAAC,KAAa;;QACnB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;QACrC,MAAA,IAAI,CAAC,QAAQ,0CAAE,kBAAkB,CAAC,IAAI,EAAE,KAAK,EAAE;IACjD,CAAC;CACF","sourcesContent":["import { DonationPaymentInfo, DonationType } from '@internetarchive/donation-form-data-models';\n\nimport currency from 'currency.js';\n\n/**\n * PayPayButtonDataSource is responsible for communicating with the PayPal button.\n *\n * The PayPal button cannot live in the ShadowDOM so we have to instantiate it at the\n * top of the DOM and it lives in the global sphere. This makes it difficult to communicate\n * with it directly. The PayPalButtonDataSource provides an object that we can pass around\n * that hooks into all of the PayPal button's callbacks and provides callbacks to its\n * delegate that is interested in the various events.\n *\n * @export\n * @interface PayPalButtonDataSourceInterface\n */\nexport interface PayPalButtonDataSourceInterface {\n /**\n * The delegate to inform about button events\n *\n * @type {PayPalButtonDataSourceDelegate}\n * @memberof PayPalButtonDataSourceInterface\n */\n delegate?: PayPalButtonDataSourceDelegate;\n\n /**\n * The Donation Info associated with this button.\n *\n * Since the user initiates the checkout flow from the button itself (not programatically by us),\n * we need to have up-to-date donation information so whenever the user updates donation info\n * from the form, we update this.\n *\n * @type {DonationPaymentInfo}\n * @memberof PayPalButtonDataSourceInterface\n */\n donationInfo: DonationPaymentInfo;\n\n /**\n * The payment has been started by the user (they clicked the PayPal button)\n *\n * @returns {Promise<string>}\n * @memberof PayPalButtonDataSourceInterface\n */\n payment(): Promise<string>;\n\n /**\n * The user has authorized the donation\n *\n * @param {paypal.AuthorizationData} data\n * @param {object} actions\n * @returns {(Promise<paypal.TokenizePayload | undefined>)}\n * @memberof PayPalButtonDataSourceInterface\n */\n onAuthorize(\n data: paypal.AuthorizationData,\n actions: object,\n ): Promise<paypal.TokenizePayload | undefined>;\n\n /**\n * The user cancelled the donation\n *\n * @param {paypal.CancellationData} data\n * @memberof PayPalButtonDataSourceInterface\n */\n onCancel(data: paypal.CancellationData): void;\n\n /**\n * An error occurred\n *\n * @param {string} error\n * @memberof PayPalButtonDataSourceInterface\n */\n onError(error: string): void;\n}\n\n/**\n * The PayPalButtonDataSourceDelegate is an interface for any object interested\n * in events emitted by the paypal button.\n *\n * @export\n * @interface PayPalButtonDataSourceDelegate\n */\nexport interface PayPalButtonDataSourceDelegate {\n /**\n * Payment has been started\n *\n * @param {PayPalButtonDataSourceInterface} dataSource\n * @param {object} options\n * @returns {Promise<void>}\n * @memberof PayPalButtonDataSourceDelegate\n */\n payPalPaymentStarted(dataSource: PayPalButtonDataSourceInterface, options: object): Promise<void>;\n\n /**\n * Payment has been authorized\n *\n * @param {PayPalButtonDataSourceInterface} dataSource\n * @param {paypal.TokenizePayload} payload\n * @returns {Promise<void>}\n * @memberof PayPalButtonDataSourceDelegate\n */\n payPalPaymentAuthorized(\n dataSource: PayPalButtonDataSourceInterface,\n payload: paypal.TokenizePayload,\n ): Promise<void>;\n\n /**\n * Payment has been cancelled\n *\n * @param {PayPalButtonDataSourceInterface} dataSource\n * @param {object} data\n * @returns {Promise<void>}\n * @memberof PayPalButtonDataSourceDelegate\n */\n payPalPaymentCancelled(dataSource: PayPalButtonDataSourceInterface, data: object): Promise<void>;\n\n /**\n * There was a payment error\n *\n * @param {PayPalButtonDataSourceInterface} dataSource\n * @param {string} error\n * @returns {Promise<void>}\n * @memberof PayPalButtonDataSourceDelegate\n */\n payPalPaymentError(dataSource: PayPalButtonDataSourceInterface, error: string): Promise<void>;\n}\n\n/** @inheritdoc */\nexport class PayPalButtonDataSource implements PayPalButtonDataSourceInterface {\n /** @inheritdoc */\n delegate?: PayPalButtonDataSourceDelegate;\n\n /** @inheritdoc */\n donationInfo: DonationPaymentInfo;\n\n /**\n * The PayPal instance\n *\n * @private\n * @type {braintree.PayPalCheckout}\n * @memberof PayPalButtonDataSource\n */\n private paypalInstance: braintree.PayPalCheckout;\n\n constructor(options: {\n donationInfo: DonationPaymentInfo;\n paypalInstance: braintree.PayPalCheckout;\n }) {\n this.donationInfo = options.donationInfo;\n this.paypalInstance = options.paypalInstance;\n }\n\n /** @inheritdoc */\n async payment(): Promise<string> {\n const donationType = this.donationInfo.donationType;\n const flow = donationType === DonationType.OneTime ? 'checkout' : 'vault';\n\n const options: braintree.PayPalCheckoutCreatePaymentOptions = {\n flow: flow as paypal.FlowType,\n intent: 'capture',\n };\n options.enableShippingAddress = true;\n\n if (flow === 'checkout') {\n options.amount = this.donationInfo.total;\n options.currency = 'USD';\n } else {\n options.billingAgreementDescription = `Subscribe to donate ${currency(\n this.donationInfo.total,\n { symbol: '$' },\n ).format()} monthly`;\n }\n\n this.delegate?.payPalPaymentStarted(this, options);\n\n return this.paypalInstance.createPayment(options);\n }\n\n /** @inheritdoc */\n async onAuthorize(data: paypal.AuthorizationData): Promise<paypal.TokenizePayload> {\n const payload: paypal.TokenizePayload = await this.paypalInstance.tokenizePayment(data);\n\n this.delegate?.payPalPaymentAuthorized(this, payload);\n\n return payload;\n }\n\n /** @inheritdoc */\n onCancel(data: object): void {\n this.delegate?.payPalPaymentCancelled(this, data);\n }\n\n /** @inheritdoc */\n onError(error: string): void {\n console.error('PayPal error', error);\n this.delegate?.payPalPaymentError(this, error);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/donation-form",
3
- "version": "0.5.10",
3
+ "version": "0.5.11",
4
4
  "description": "The Internet Archive Donation Form",
5
5
  "license": "AGPL-3.0-only",
6
6
  "main": "dist/index.js",
package/src/.DS_Store CHANGED
Binary file
@@ -1,7 +1,4 @@
1
- export enum LineItemKind {
2
- Debit = 'debit',
3
- Credit = 'credit',
4
- }
1
+ export type LineItemKind = 'debit' | 'credit';
5
2
 
6
3
  export interface LineItem {
7
4
  /**
@@ -45,17 +42,7 @@ export interface LineItem {
45
42
  url: string | undefined;
46
43
  }
47
44
 
48
- export enum ShippingOptionType {
49
- /**
50
- * The payer intends to receive the items at a specified address.
51
- */
52
- Shipping = 'SHIPPING',
53
-
54
- /**
55
- * The payer intends to pick up the items at a specified address. For example, a store address.
56
- */
57
- Pickup = 'PICKUP',
58
- }
45
+ export type ShippingOptionType = 'SHIPPING' | 'PICKUP';
59
46
 
60
47
  export interface CurrencyAmount {
61
48
  /**
@@ -219,37 +206,9 @@ export interface TokenizePayload {
219
206
  details: TokenizePayloadDetails;
220
207
  }
221
208
 
222
- export enum FlowType {
223
- /**
224
- * Used to store the payment method for future use, ie subscriptions
225
- */
226
- Vault = 'vault',
227
-
228
- /**
229
- * Used for one-time checkout
230
- */
231
- Checkout = 'checkout',
232
- }
233
-
234
- export enum Intent {
235
- /**
236
- * Submits the transaction for authorization but not settlement.
237
- */
238
- Authorize = 'authorize',
209
+ export type FlowType = 'checkout' | 'vault';
239
210
 
240
- /**
241
- * Validates the transaction without an authorization (i.e. without holding funds).
242
- * Useful for authorizing and capturing funds up to 90 days after the order has been placed.
243
- * Only available for Checkout flow.
244
- */
245
- Order = 'order',
246
-
247
- /**
248
- * Payment will be immediately submitted for settlement upon creating a transaction.
249
- * `sale` can be used as an alias for this value.
250
- */
251
- Capture = 'capture',
252
- }
211
+ export type Intent = 'authorize' | 'order' | 'capture';
253
212
 
254
213
  export interface AuthorizationData {
255
214
  payerId: string;
@@ -157,6 +157,7 @@ export class PayPalButtonDataSource implements PayPalButtonDataSourceInterface {
157
157
 
158
158
  const options: braintree.PayPalCheckoutCreatePaymentOptions = {
159
159
  flow: flow as paypal.FlowType,
160
+ intent: 'capture',
160
161
  };
161
162
  options.enableShippingAddress = true;
162
163