Skip to content

Commit

Permalink
fix(payments-plugin): Fix null access error in BraintreePlugin
Browse files Browse the repository at this point in the history
Gracefully handles the case where the call to create a sale
fails, and there is no `transaction` object available.
  • Loading branch information
michaelbromley committed Jan 21, 2025
1 parent e22c601 commit 627d930
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/payments-plugin/src/braintree/braintree.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ async function processPayment(
},
});
const extractMetadataFn = pluginOptions.extractMetadata ?? defaultExtractMetadataFn;
const metadata = extractMetadataFn(response.transaction);
const metadata = response.transaction && extractMetadataFn(response.transaction);
if (!response.success) {
return {
amount,
state: 'Declined' as const,
transactionId: response.transaction.id,
transactionId: response.transaction?.id,
errorMessage: response.message,
metadata,
};
Expand Down

0 comments on commit 627d930

Please sign in to comment.