Parcourir la source

fix(payments-plugin): Fix null access error in BraintreePlugin

Gracefully handles the case where the call to create a sale
fails, and there is no `transaction` object available.
Michael Bromley il y a 1 an
Parent
commit
627d930a2f
1 fichiers modifiés avec 2 ajouts et 2 suppressions
  1. 2 2
      packages/payments-plugin/src/braintree/braintree.handler.ts

+ 2 - 2
packages/payments-plugin/src/braintree/braintree.handler.ts

@@ -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,
         };