Skip to content

Commit

Permalink
breaking: remove Constants.API_VERSION.ISSUING in favor of getIssuing…
Browse files Browse the repository at this point in the history
…ApiVersion
  • Loading branch information
charliecruzan-stripe committed Sep 13, 2023
1 parent 4178490 commit 12fc3d2
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

**Breaking changes**

- `Constants.API_VERSIONS.ISSUING` has been removed, please use the asynchronous `getIssuingApiVersion` method instead. This should improve app startup time.

**Features**

- `createPlatformPayPaymentMethod` and `createPlatformPayToken` now also include an optional `shippingContact` field in their results. [#1500](https://github.com/stripe/stripe-react-native/pull/1500)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,16 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
hashMapOf(
"API_VERSIONS" to hashMapOf(
"CORE" to ApiVersion.API_VERSION_CODE,
"ISSUING" to PushProvisioningProxy.getApiVersion(),
)
)

@ReactMethod
fun getIssuingApiVersion(promise: Promise) {
promise.resolve(
PushProvisioningProxy.getApiVersion()
)
}

@ReactMethod
fun initialise(params: ReadableMap, promise: Promise) {
val publishableKey = getValOr(params, "publishableKey", null) as String
Expand Down
5 changes: 3 additions & 2 deletions example/src/screens/ApplePayScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Alert, StyleSheet, Text, View } from 'react-native';
import {
PlatformPay,
AddToWalletButton,
Constants,
getIssuingApiVersion,
canAddCardToWallet,
PlatformPayButton,
usePlatformPay,
Expand Down Expand Up @@ -194,13 +194,14 @@ export default function ApplePayScreen() {
};

const fetchEphemeralKey = async () => {
const issuingApiVersion = await getIssuingApiVersion();
const response = await fetch(`${API_URL}/ephemeral-key`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
apiVersion: Constants.API_VERSIONS.ISSUING,
apiVersion: issuingApiVersion,
issuingCardId: TEST_CARD_ID,
}),
});
Expand Down
5 changes: 3 additions & 2 deletions example/src/screens/GooglePayScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useEffect, useState } from 'react';
import {
AddToWalletButton,
Constants,
canAddCardToWallet,
createPlatformPayPaymentMethod,
createPlatformPayToken,
Expand All @@ -10,6 +9,7 @@ import {
isPlatformPaySupported,
PlatformPay,
PlatformPayButton,
getIssuingApiVersion,
} from '@stripe/stripe-react-native';
import PaymentScreen from '../components/PaymentScreen';
import { API_URL } from '../Config';
Expand Down Expand Up @@ -183,13 +183,14 @@ export default function GooglePayScreen() {
};

const fetchEphemeralKey = async () => {
const issuingApiVersion = await getIssuingApiVersion();
const response = await fetch(`${API_URL}/ephemeral-key`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
apiVersion: Constants.API_VERSIONS.ISSUING,
apiVersion: issuingApiVersion,
issuingCardId: LIVE_CARD_ID,
}),
});
Expand Down
4 changes: 4 additions & 0 deletions ios/StripeSdk.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ @interface RCT_EXTERN_MODULE(StripeSdk, RCTEventEmitter)
resolver: (RCTPromiseResolveBlock)resolve
rejecter: (RCTPromiseRejectBlock)reject
)
RCT_EXTERN_METHOD(
getIssuingApiVersion:(RCTPromiseResolveBlock)resolve
rejecter: (RCTPromiseRejectBlock)reject
)
RCT_EXTERN_METHOD(
isCardInWallet:(NSDictionary *)params
resolver: (RCTPromiseResolveBlock)resolve
Expand Down
6 changes: 5 additions & 1 deletion ios/StripeSdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,14 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
return [
"API_VERSIONS": [
"CORE": STPAPIClient.apiVersion,
"ISSUING": STPAPIClient.apiVersion,
]
]
}

@objc(getIssuingApiVersion:rejecter:)
func getIssuingApiVersion(resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
resolve(STPAPIClient.apiVersion)
}

@objc(initialise:resolver:rejecter:)
func initialise(params: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
Expand Down
1 change: 1 addition & 0 deletions jest/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const mockFunctions = {
details: null,
error: null,
})),
getIssuingApiVersion: jest.fn(async () => ''),
isCardInWallet: jest.fn(async () => ({
isInWallet: false,
token: {},
Expand Down
3 changes: 2 additions & 1 deletion src/NativeStripeSdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ type NativeStripeSdkType = {
clientSecret: string,
params: PaymentMethod.CollectBankAccountParams
): Promise<ConfirmSetupIntentResult | ConfirmPaymentResult>;
getConstants(): { API_VERSIONS: { CORE: string; ISSUING: string } };
getConstants(): { API_VERSIONS: { CORE: string } };
canAddCardToWallet(
params: CanAddCardToWalletParams
): Promise<CanAddCardToWalletResult>;
getIssuingApiVersion(): Promise<string>;
isCardInWallet(params: {
cardLastFour: string;
}): Promise<IsCardInWalletResult>;
Expand Down
9 changes: 9 additions & 0 deletions src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,15 @@ export const canAddCardToWallet = async (
}
};

/**
* Get the supported Stripe API version for usage on your server with Issuing-related API calls.
* @returns A string representing the supported API version, or an empty string if
* the required push provisioning dependencies are not found.
*/
export const getIssuingApiVersion = async (): Promise<string> => {
return await NativeStripeSdk.getIssuingApiVersion();
};

/** @deprecated Please use `canAddCardToWallet` instead. */
export const isCardInWallet = async (params: {
cardLastFour: string;
Expand Down
16 changes: 16 additions & 0 deletions src/hooks/usePlatformPay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function usePlatformPay() {
dismissPlatformPay,
updatePlatformPaySheet,
canAddCardToWallet,
getIssuingApiVersion,
openPlatformPaySetup,
} = useStripe();
const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -124,6 +125,15 @@ export function usePlatformPay() {
[canAddCardToWallet]
);

const _getIssuingApiVersion = useCallback(async (): Promise<string> => {
setLoading(true);

const result = await getIssuingApiVersion();
setLoading(false);

return result;
}, [getIssuingApiVersion]);

const _openPlatformPaySetup = useCallback(async (): Promise<void> => {
return openPlatformPaySetup();
}, [openPlatformPaySetup]);
Expand Down Expand Up @@ -183,6 +193,12 @@ export function usePlatformPay() {
* @returns A promise resolving to an object of type CanAddCardToWalletResult. Check the `canAddCard` field, if it's true, you should show the `<AddToWalletButton />`
*/
canAddCardToWallet: _canAddCardToWallet,
/**
* Get the supported Stripe API version for usage on your server with Issuing-related API calls.
* @returns A string representing the supported API version, or an empty string if
* the required push provisioning dependencies are not found.
*/
getIssuingApiVersion: _getIssuingApiVersion,
/**
* iOS only, this is a no-op on Android. Use this method to move users to the interface for adding credit cards.
* This method transfers control to the Wallet app on iPhone or to the Settings
Expand Down
6 changes: 6 additions & 0 deletions src/hooks/useStripe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
verifyMicrodepositsForPayment,
verifyMicrodepositsForSetup,
canAddCardToWallet,
getIssuingApiVersion,
collectBankAccountToken,
collectFinancialConnectionsAccounts,
resetPaymentSheetCustomer,
Expand Down Expand Up @@ -224,6 +225,10 @@ export function useStripe() {
[]
);

const _getIssuingApiVersion = useCallback(async (): Promise<string> => {
return getIssuingApiVersion();
}, []);

const _collectBankAccountToken = useCallback(
async (clientSecret: string): Promise<FinancialConnections.TokenResult> => {
return collectBankAccountToken(clientSecret);
Expand Down Expand Up @@ -333,6 +338,7 @@ export function useStripe() {
verifyMicrodepositsForPayment: _verifyMicrodepositsForPayment,
verifyMicrodepositsForSetup: _verifyMicrodepositsForSetup,
canAddCardToWallet: _canAddCardToWallet,
getIssuingApiVersion: _getIssuingApiVersion,
collectBankAccountToken: _collectBankAccountToken,
collectFinancialConnectionsAccounts: _collectFinancialConnectionsAccounts,
/**
Expand Down

0 comments on commit 12fc3d2

Please sign in to comment.