|
| 1 | +import { callback } from './core'; |
| 2 | +import { Client } from './client'; |
| 3 | + |
| 4 | +export type LocalPaymentTypes = |
| 5 | + | 'bancontact' |
| 6 | + | 'blik' |
| 7 | + | 'eps' |
| 8 | + | 'giropay' |
| 9 | + | 'ideal' |
| 10 | + | 'sofort' |
| 11 | + | 'mybank' |
| 12 | + | 'p24' |
| 13 | + | 'trustly'; |
| 14 | + |
| 15 | +export interface LocalPaymentTokenizePayload { |
| 16 | + correlationId: string; |
| 17 | + nonce: string; |
| 18 | + details: unknown; |
| 19 | + type: string; |
| 20 | +} |
| 21 | + |
| 22 | +export interface LocalPaymentAddress { |
| 23 | + streetAddress?: string | undefined; |
| 24 | + extendedAddress?: string | undefined; |
| 25 | + locality?: string | undefined; |
| 26 | + region?: string | undefined; |
| 27 | + postalCode?: string | undefined; |
| 28 | + countryCode?: string | undefined; |
| 29 | +} |
| 30 | + |
| 31 | +export interface LocalPaymentFallback { |
| 32 | + buttonText?: string | undefined; |
| 33 | + url?: string | undefined; |
| 34 | + cancelButtonText?: string | undefined; |
| 35 | + cancelUrl?: string | undefined; |
| 36 | +} |
| 37 | + |
| 38 | +export interface LocalPaymentStartData { |
| 39 | + paymentId: string; |
| 40 | +} |
| 41 | + |
| 42 | +export interface LocalPaymentStartPaymentOptions { |
| 43 | + amount: string | number; |
| 44 | + currencyCode: string; |
| 45 | + paymentType: LocalPaymentTypes; |
| 46 | + fallback?: LocalPaymentFallback | undefined; |
| 47 | + windowOptions?: |
| 48 | + | { |
| 49 | + width?: number | undefined; |
| 50 | + height?: number | undefined; |
| 51 | + } |
| 52 | + | undefined; |
| 53 | + givenName?: string | undefined; |
| 54 | + surname?: string | undefined; |
| 55 | + displayName?: string | undefined; |
| 56 | + countryCode?: string | undefined; |
| 57 | + paymentTypeCountryCode?: string | undefined; |
| 58 | + email?: string | undefined; |
| 59 | + phone?: string | undefined; |
| 60 | + bic?: string | undefined; |
| 61 | + shippingAddressRequired?: boolean | undefined; |
| 62 | + address?: LocalPaymentAddress | undefined; |
| 63 | + onPaymentStart?: ((data: LocalPaymentStartData, callback: callback) => void) | undefined; |
| 64 | +} |
| 65 | + |
| 66 | +export interface LocalPaymentTokenizeOptions { |
| 67 | + btLpToken?: string | undefined; |
| 68 | + btLpPaymentId?: string | undefined; |
| 69 | + btLpPayerId?: string | undefined; |
| 70 | +} |
| 71 | + |
| 72 | +export interface LocalPaymentCreateOptions { |
| 73 | + authorization?: string | undefined; |
| 74 | + client?: Client | undefined; |
| 75 | + merchantAccountId?: string | undefined; |
| 76 | +} |
| 77 | + |
| 78 | +export interface LocalPayment { |
| 79 | + /** |
| 80 | + * braintree.localPayment.create({ |
| 81 | + * client: client |
| 82 | + * }, callback) |
| 83 | + */ |
| 84 | + create(options: LocalPaymentCreateOptions): Promise<LocalPayment>; |
| 85 | + create(options: LocalPaymentCreateOptions, callback: callback<LocalPayment>): void; |
| 86 | + |
| 87 | + /** |
| 88 | + * The current version of the SDK, i.e. 3.84.0. |
| 89 | + */ |
| 90 | + VERSION: string; |
| 91 | + |
| 92 | + /** |
| 93 | + * Closes the LocalPayment window if it is open. |
| 94 | + * @example |
| 95 | + * localPaymentInstance.closeWindow(); |
| 96 | + */ |
| 97 | + closeWindow(): void; |
| 98 | + |
| 99 | + /** |
| 100 | + * Focuses the LocalPayment window if it is open. |
| 101 | + * @example |
| 102 | + * localPaymentInstance.focusWindow(); |
| 103 | + */ |
| 104 | + focusWindow(): void; |
| 105 | + |
| 106 | + /** |
| 107 | + * Checks if required tokenization parameters are available in querystring for manual tokenization requests. |
| 108 | + * @example |
| 109 | + * // if query string contains |
| 110 | + * // ?btLpToken=token&btLpPaymentId=payment-id&btLpPayerId=payer-id |
| 111 | + * localPaymentInstance.hasTokenizationParams(); // true |
| 112 | + * // if query string is missing required params |
| 113 | + * localPaymentInstance.hasTokenizationParams(); // false |
| 114 | + * if (localPaymentInstance.hasTokenizationParams()) { |
| 115 | + * localPaymentInstance.tokenize(); |
| 116 | + * } |
| 117 | + */ |
| 118 | + hasTokenizationParams(): boolean; |
| 119 | + |
| 120 | + /** |
| 121 | + * Launches the local payment flow and returns a nonce payload. Only one local payment flow should be active at a time. |
| 122 | + * One way to achieve this is to disable your local payment button while the flow is open. |
| 123 | + * @example |
| 124 | + * button.addEventListener('click', function () { |
| 125 | + * // Disable the button when local payment is in progress |
| 126 | + * button.setAttribute('disabled', 'disabled'); |
| 127 | + * // Because startPayment opens a new window, this must be called |
| 128 | + * // as a result of a user action, such as a button click. |
| 129 | + * localPaymentInstance.startPayment({ |
| 130 | + * paymentType: 'ideal', |
| 131 | + * paymentTypeCountryCode: 'NL', |
| 132 | + * fallback: { |
| 133 | + * buttonText: 'Return to Merchant', |
| 134 | + * url: 'https://example.com/my-checkout-page' |
| 135 | + * }, |
| 136 | + * amount: '10.00', |
| 137 | + * currencyCode: 'EUR', |
| 138 | + * onPaymentStart: function (data, continueCallback) { |
| 139 | + * // Do any preprocessing before starting the flow |
| 140 | + * // data.paymentId is the ID of the localPayment |
| 141 | + * continueCallback(); |
| 142 | + * } |
| 143 | + * }).then(function (payload) { |
| 144 | + * button.removeAttribute('disabled'); |
| 145 | + * // Submit payload.nonce to your server |
| 146 | + * }).catch(function (startPaymentError) { |
| 147 | + * button.removeAttribute('disabled'); |
| 148 | + * // Handle flow errors or premature flow closure |
| 149 | + * console.error('Error!', startPaymentError); |
| 150 | + * }); |
| 151 | + * }); |
| 152 | + */ |
| 153 | + startPayment(options: LocalPaymentStartPaymentOptions): Promise<LocalPaymentTokenizePayload>; |
| 154 | + startPayment(options: LocalPaymentStartPaymentOptions, callback?: callback<LocalPaymentTokenizePayload>): void; |
| 155 | + |
| 156 | + /** |
| 157 | + * Cleanly remove anything set up by {@link module:braintree-web/local-payment.create|create}. |
| 158 | + * @example |
| 159 | + * localPaymentInstance.teardown(); |
| 160 | + * @example <caption>With callback</caption> |
| 161 | + * localPaymentInstance.teardown(function () { |
| 162 | + * // teardown is complete |
| 163 | + * }); |
| 164 | + */ |
| 165 | + teardown(callback?: callback): void; |
| 166 | + teardown(): Promise<void>; |
| 167 | + |
| 168 | + /** |
| 169 | + * Manually tokenizes params for a local payment received from PayPal. |
| 170 | + * When app switching back from a mobile application (such as a bank application for an iDEAL payment) the window may lose context with the parent page. |
| 171 | + * In that case, a fallback url is used, and this method can be used to finish the flow. |
| 172 | + * @example |
| 173 | + * localPaymentInstance.tokenize().then(function (payload) { |
| 174 | + * // send payload.nonce to your server |
| 175 | + * }).catch(function (err) { |
| 176 | + * // handle tokenization error |
| 177 | + * }); |
| 178 | + */ |
| 179 | + tokenize(params?: LocalPaymentTokenizeOptions): Promise<LocalPaymentTokenizePayload>; |
| 180 | + tokenize(params?: LocalPaymentTokenizeOptions, callback?: callback<LocalPaymentTokenizePayload>): void; |
| 181 | +} |
0 commit comments