Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ presentEntirePaymentFlow(session)
| `payWithCardDetails(session, card, saveCard)` | Your own card UI (PCI-DSS required) |
| `payWithConsent(session, consent)` | Charge a previously saved payment consent |

Session `type` can be `'OneOff'`, `'Recurring'` (save a method without charging), or `'RecurringWithIntent'` (charge now and save). Optionally pass `{ layout: 'tab' | 'accordion' }` as the second argument to `presentEntirePaymentFlow`.
Session `type` can be `'OneOff'`, `'Recurring'` (save a method without charging), or `'RecurringWithIntent'` (charge now and save). Optionally pass a configuration as the second argument to `presentEntirePaymentFlow`:

```ts
presentEntirePaymentFlow(session, {
layout: 'tab', // or 'accordion'
checkoutButton: { title: 'Pay HKD 50.00' }, // optional, defaults to "Pay" / "Confirm"
});
```

A runnable integration lives in [`example/`](./example).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ object PaymentSheetConfigurationConverter {
"accordion" -> PaymentMethodsLayoutType.ACCORDION
else -> PaymentMethodsLayoutType.TAB
}
return PaymentElementConfiguration.PaymentSheet(layout = layout)
val checkoutButtonTitle = map?.getMapOrNull("checkoutButton")?.getStringOrNull("title")
val checkoutButton = checkoutButtonTitle?.let { PaymentElementConfiguration.CheckoutButton(it) }
?: PaymentElementConfiguration.CheckoutButton()
return PaymentElementConfiguration.PaymentSheet(layout = layout, checkoutButton = checkoutButton)
}
}
17 changes: 17 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,23 @@ function Main() {
PresentEntirePaymentFlow (accordion)
</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
handlePaymentFlowPress((session) =>
presentEntirePaymentFlow(session, {
layout: 'tab',
checkoutButton: {
title: `Pay ${session.currency} ${session.amount.toFixed(2)}`,
},
})
);
}}
>
<Text style={styles.buttonText}>
PresentEntirePaymentFlow (custom button)
</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
Expand Down
4 changes: 4 additions & 0 deletions ios/AWXUIContextConfiguration+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ extension AWXUIContext.Configuration {
} else {
layout = .tab
}
if let checkoutButton = params?["checkoutButton"] as? NSDictionary,
let title = checkoutButton["title"] as? String {
self.checkoutButton.title = title
}
}
}
12 changes: 12 additions & 0 deletions src/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { OneOffSession } from '../types/PaymentSession';
import type { PaymentSheetConfiguration } from '../types/PaymentSheetConfiguration';

describe('PaymentSession', () => {
it('includes lang when provided', () => {
Expand All @@ -15,3 +16,14 @@ describe('PaymentSession', () => {
expect(session.lang).toBe('zh-Hans');
});
});

describe('PaymentSheetConfiguration', () => {
it('accepts a custom checkout button title', () => {
const configuration: PaymentSheetConfiguration = {
layout: 'tab',
checkoutButton: { title: 'Pay HKD 50.00' },
};

expect(configuration.checkoutButton?.title).toBe('Pay HKD 50.00');
});
});
13 changes: 13 additions & 0 deletions src/types/PaymentSheetConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,17 @@ export type PaymentLayout = 'tab' | 'accordion';
*/
export interface PaymentSheetConfiguration {
layout: PaymentLayout;
/** Customizes the checkout button at the bottom of the payment sheet. */
checkoutButton?: CheckoutButtonConfiguration;
}

/**
* Checkout button options for the payment sheet.
*/
export interface CheckoutButtonConfiguration {
/**
* Custom button title, e.g. `'Pay HKD 50.00'`. When omitted, the SDK uses its default:
* "Pay" for one-off payments and "Confirm" for recurring ones.
*/
title?: string;
}
Loading