Skip to content

Commit

Permalink
chore: update types for expanded apple pay options
Browse files Browse the repository at this point in the history
  • Loading branch information
cbarton committed Mar 25, 2023
1 parent 29f9f9d commit 266d931
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 6 deletions.
11 changes: 10 additions & 1 deletion test/types/apple-pay.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
export default function applePay() {
const applePay = recurly.ApplePay({
const applePayDeprecated = recurly.ApplePay({
country: 'US',
currency: 'USD',
label: 'My Subscription',
total: '29.00',
pricing: window.recurly.Pricing.Checkout()
});

const applePay = recurly.ApplePay({
country: 'US',
currency: 'USD',
total: { label: 'My Subscription', amount: '29.00' },
lineItems: [{ label: 'Subtotal', amount: '1.00' }],
requiredShippingContactFields: ['email', 'phone'],
pricing: window.recurly.Pricing.Checkout()
});

applePay.ready(() => {});
// @ts-expect-error
applePay.ready(arg => {});
Expand Down
16 changes: 11 additions & 5 deletions types/lib/apple-pay.d.ts → types/lib/apple-pay/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Emitter } from './emitter';
import { CheckoutPricingInstance, CheckoutPricingPromise } from './pricing/checkout';
import { Emitter } from '../emitter';
import { CheckoutPricingInstance, CheckoutPricingPromise } from '../pricing/checkout';
import { ApplePayPaymentRequest } from './native';

export type ApplePayConfig = {
/**
Expand All @@ -15,12 +16,12 @@ export type ApplePayConfig = {
/**
* Purchase description to display in the Apple Pay payment sheet.
*/
label: string;
label?: string;

/**
* Total cost to display in the Apple Pay payment sheet. Required if `options.pricing` is not provided.
*/
total: string;
total?: string;

/**
* If provided, will override `options.total` and provide the current total price on the CheckoutPricing instance
Expand All @@ -37,13 +38,18 @@ export type ApplePayConfig = {
*/
form?: HTMLFormElement;

/**
* If `options.requiredShippingContactFields` is present, validate that the browser supports the minimum version required for that option.
*/
enforceVersion?: boolean;

/**
* If provided, will use Braintree to process the ApplePay transaction.
*/
braintree?: {
clientAuthorization: string;
};
};
} | ApplePayPaymentRequest;

export type ApplePayEvent =
| 'token'
Expand Down
77 changes: 77 additions & 0 deletions types/lib/apple-pay/native.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* A type that indicates the time a payment occurs in a transaction.
*/
export type ApplePayPaymentTiming =
| 'immediate'
| 'recurring';

/**
* A type that indicates calendrical units, such as year, month, day, and hour.
*/
export type ApplePayRecurringPaymentDateUnit =
| 'year'
| 'month';

/**
* Field names for requesting contact information in a payment request.
*/
export type ApplePayContactField =
| 'email'
| 'name'
| 'phone'
| 'postalAddress'
| 'phoneticName';

export type ApplePayLineItem = {
/**
* A required value that’s a short, localized description of the line item.
*/
label: string;

/**
* A required value that’s the monetary amount of the line item.
*/
amount: string;

/**
* The time that the payment occurs as part of a successful transaction.
*/
paymentTiming?: ApplePayPaymentTiming;

/**
* The date of the first payment.
*/
recurringPaymentStartDate?: Date;

/**
* The amount of time — in calendar units, such as day, month, or year — that represents a fraction of the total payment interval.
*/
recurringPaymentIntervalUnit?: ApplePayRecurringPaymentDateUnit;

/**
* The number of interval units that make up the total payment interval.
*/
recurringPaymentIntervalCount?: number;

/**
* The date of the final payment.
*/
recurringPaymentEndDate?: Date;
};

export type ApplePayPaymentRequest = {
/**
* Total cost to display in the Apple Pay payment sheet. Required if `options.pricing` is not provided.
*/
total: ApplePayLineItem;

/**
* The fields of shipping information the user must provide to fulfill the order.
*/
requiredShippingContactFields?: ApplePayContactField[];

/**
* A set of line items that explain recurring payments and additional charges and discounts.
*/
lineItems?: ApplePayLineItem[];
};

0 comments on commit 266d931

Please sign in to comment.