Skip to content

Commit

Permalink
Fix 4 (#52)
Browse files Browse the repository at this point in the history
* fix

* fix
  • Loading branch information
syvlabs authored Oct 5, 2024
1 parent 58849b4 commit 6c418b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions lib/hooks/use-payment-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ export const usePaymentRequests = (
return;
}

const stripeCpm = availableCPMs.find(
const allStripeCPMs = availableCPMs.filter(
(cpm) =>
cpm.processor_name === 'stripe' && PaymentRequestProvider.options.map((s) => String(s)).includes(cpm.provider)
);
if (!stripeCpm) {
if (allStripeCPMs.length === 0) {
throw new Error(`Stripe is not available as a checkout method`);
}
const stripePubKey = parseStripePubKey(stripeCpm.metadata);
const stripePubKey = parseStripePubKey(allStripeCPMs[0].metadata);
const prefill = await getPrefill(cdeConn);
const isSetupMode = prefill.mode === 'setup';
setIsSetupMode(isSetupMode);
Expand All @@ -109,11 +109,15 @@ export const usePaymentRequests = (
const providerFriendlyName = provider.replace('_', '');
console.log(`Processing provider ${providerFriendlyName}`);
try {
const cpm = allStripeCPMs.find((cpm) => cpm.provider === provider);
if (!cpm) {
throw new Error(`${provider} is not available as a stripe checkout method`);
}
setStatus.set(provider, {
isLoading: false,
isAvailable: canMakePayment?.[OUR_PROVIDER_TO_STRIPES[provider]] ?? false,
startFlow: (params?: PaymentRequestStartParams) =>
startPaymentRequestUserFlow(formDiv, stripeCpm, onUserCompleteUIFlow, onValidationError, onError, params),
startPaymentRequestUserFlow(formDiv, cpm, onUserCompleteUIFlow, onValidationError, onError, params),
});
} catch (e) {
console.error(e);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@getopenpay/openpay-js-react",
"version": "0.0.20",
"version": "0.0.21",
"description": "Accept payments through OpenPay, right on your site",
"author": "OpenPay <info@getopenpay.com> (https://getopenpay.com)",
"type": "module",
Expand Down

0 comments on commit 6c418b5

Please sign in to comment.