Skip to content

Commit

Permalink
[dev app] pass on incremental/extended auth params and update stripe …
Browse files Browse the repository at this point in the history
…dependency (#479)

* bump stripe version

* pass incremental/extended auth params

* update stripe to latest in devapp
  • Loading branch information
lins-stripe authored Jun 6, 2023
1 parent 4d39a8b commit f40aa87
Show file tree
Hide file tree
Showing 4 changed files with 929 additions and 897 deletions.
2 changes: 1 addition & 1 deletion dev-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
"concurrently": "^7.0.0",
"detox": "^19.4.3",
"metro-react-native-babel-preset": "^0.67.0",
"stripe": "^8.181.0"
"stripe": "^12.8.0"
}
}
43 changes: 33 additions & 10 deletions dev-app/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class Api {
label: string;
registrationCode: string;
location: string | null | undefined;
}): Promise<Stripe.Terminal.Reader | { error: Stripe.StripeAPIError }> {
}): Promise<Stripe.Terminal.Reader | { error: Stripe.StripeRawError }> {
const formData = new URLSearchParams();
formData.append('label', label);
formData.append('registration_code', registrationCode);
Expand All @@ -53,7 +53,7 @@ export class Api {
description?: string;
paymentMethodTypes?: string;
customer?: string;
}): Promise<Stripe.SetupIntent | { error: Stripe.StripeAPIError }> {
}): Promise<Stripe.SetupIntent | { error: Stripe.StripeRawError }> {
const formData = new URLSearchParams();
formData.append('description', description);

Expand All @@ -77,7 +77,7 @@ export class Api {
async capturePaymentIntent(
id: string,
{ amount_to_capture }: Stripe.PaymentIntentCaptureParams
): Promise<Stripe.PaymentIntent | { error: Stripe.StripeAPIError }> {
): Promise<Stripe.PaymentIntent | { error: Stripe.StripeRawError }> {
const formData = new URLSearchParams();

if (amount_to_capture) {
Expand All @@ -96,10 +96,11 @@ export class Api {
currency = 'usd',
description = 'Example PaymentIntent',
payment_method_types,
payment_method_options,
setup_future_usage,
capture_method,
}: Stripe.PaymentIntentCreateParams): Promise<
Stripe.PaymentIntent | { error: Stripe.StripeError }
Stripe.PaymentIntent | { error: Stripe.StripeRawError }
> {
const formData = new URLSearchParams();
formData.append('amount', amount.toString());
Expand All @@ -118,6 +119,28 @@ export class Api {
});
}

if (payment_method_options) {
if (payment_method_options.card_present) {
if (
payment_method_options.card_present.request_extended_authorization
) {
formData.append(
'payment_method_options[card_present][request_extended_authorization]',
payment_method_options.card_present.request_extended_authorization.toString()
);
}
if (
payment_method_options.card_present
.request_incremental_authorization_support
) {
formData.append(
'payment_method_options[card_present][request_incremental_authorization_support]',
payment_method_options.card_present.request_incremental_authorization_support.toString()
);
}
}
}

// TODO: implement connect functionality to set these values
// if (
// this.connectedAccount &&
Expand Down Expand Up @@ -151,7 +174,7 @@ export class Api {
static async getAccount(
secretKey: string
): Promise<
(Stripe.Account & { secretKey: string }) | { error: Stripe.StripeAPIError }
(Stripe.Account & { secretKey: string }) | { error: Stripe.StripeRawError }
> {
const result = await fetch('https://api.stripe.com/v1/account', {
headers: {
Expand All @@ -171,7 +194,7 @@ export class Api {
}

async createConnectionToken(): Promise<
Stripe.Terminal.ConnectionToken | { error: Stripe.StripeAPIError }
Stripe.Terminal.ConnectionToken | { error: Stripe.StripeRawError }
> {
const formData = new URLSearchParams();
return fetch('https://api.stripe.com/v1/terminal/connection_tokens', {
Expand All @@ -183,7 +206,7 @@ export class Api {

async getCustomers(
email?: string
): Promise<Array<Stripe.Customer> | { error: Stripe.StripeAPIError }> {
): Promise<Array<Stripe.Customer> | { error: Stripe.StripeRawError }> {
const params = new URLSearchParams();
if (email) {
params.append('email', email);
Expand All @@ -203,7 +226,7 @@ export class Api {

async createCustomer(
email: string
): Promise<Stripe.Customer | { error: Stripe.StripeAPIError }> {
): Promise<Stripe.Customer | { error: Stripe.StripeRawError }> {
const formData = new URLSearchParams();
formData.append('email', email);

Expand All @@ -224,7 +247,7 @@ export class Api {

async getPaymentIntent(
id: string
): Promise<Stripe.PaymentIntent | { error: Stripe.StripeAPIError }> {
): Promise<Stripe.PaymentIntent | { error: Stripe.StripeRawError }> {
const formData = new URLSearchParams();

return fetch(`https://api.stripe.com/v1/payment_intents/${id}`, {
Expand All @@ -243,7 +266,7 @@ export class Api {
}

async lookupOrCreateExampleCustomer(): Promise<
Stripe.Customer | { error: Stripe.StripeAPIError }
Stripe.Customer | { error: Stripe.StripeRawError }
> {
const customerEmail = 'example@test.com';
const customerList = await this.getCustomers(customerEmail);
Expand Down
9 changes: 9 additions & 0 deletions dev-app/src/screens/CollectCardPaymentScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,22 @@ export default function CollectCardPaymentScreen() {
if (enableInterac) {
paymentMethods.push('interac_present');
}
const paymentMethodOptions = {
card_present: {
request_extended_authorization:
inputValues.requestExtendedAuthorization,
request_incremental_authorization_support:
inputValues.requestIncrementalAuthorizationSupport,
},
};
let paymentIntent: PaymentIntent.Type | undefined;
let paymentIntentError: StripeError<CommonError> | undefined;
if (discoveryMethod === 'internet') {
const resp = await api.createPaymentIntent({
amount: Number(inputValues.amount),
currency: inputValues.currency,
payment_method_types: paymentMethods,
payment_method_options: paymentMethodOptions,
capture_method: inputValues?.captureMethod,
});

Expand Down
Loading

0 comments on commit f40aa87

Please sign in to comment.