Browse Source

Revert "feat(payments-plugin): BraintreePlugin make card vault optional"

This reverts commit 16ad00cd3b3b028dedd472c987d2b7ee307a3a28.

It turns out my assumptions about the way the Braintree Node SDK work were wrong.
See https://github.com/braintree/braintree_node/issues/208
Michael Bromley 3 years ago
parent
commit
ef5d4de3ff

+ 3 - 14
packages/payments-plugin/src/braintree/braintree.handler.ts

@@ -38,27 +38,17 @@ export const braintreePaymentMethodHandler = new PaymentMethodHandler({
     async createPayment(ctx, order, amount, args, metadata) {
         const gateway = getGateway(args, options);
         let customerId: string | undefined;
-        const { nonce, storeCardInVault } = metadata;
-        if (!nonce) {
-            return {
-                amount,
-                state: 'Error' as const,
-                transactionId: '',
-                errorMessage: `No "nonce" value was specified in the metadata`,
-                metadata,
-            };
-        }
         try {
             await entityHydrator.hydrate(ctx, order, { relations: ['customer'] });
             const customer = order.customer;
             if (options.storeCustomersInBraintree && ctx.activeUserId && customer) {
                 customerId = await getBraintreeCustomerId(ctx, gateway, customer);
             }
-            return processPayment(ctx, gateway, order, amount, nonce, customerId, options, storeCardInVault);
+            return processPayment(ctx, gateway, order, amount, metadata.nonce, customerId, options);
         } catch (e) {
             Logger.error(e, loggerCtx);
             return {
-                amount,
+                amount: order.total,
                 state: 'Error' as const,
                 transactionId: '',
                 errorMessage: e.toString(),
@@ -99,7 +89,6 @@ async function processPayment(
     paymentMethodNonce: any,
     customerId: string | undefined,
     pluginOptions: BraintreePluginOptions,
-    storeCardInVault = true,
 ) {
     const response = await gateway.transaction.sale({
         customerId,
@@ -108,7 +97,7 @@ async function processPayment(
         paymentMethodNonce,
         options: {
             submitForSettlement: true,
-            storeInVaultOnSuccess: !!customerId && storeCardInVault,
+            storeInVaultOnSuccess: !!customerId,
         },
     });
     const extractMetadataFn = pluginOptions.extractMetadata ?? defaultExtractMetadataFn;

+ 0 - 42
packages/payments-plugin/src/braintree/braintree.plugin.ts

@@ -186,49 +186,7 @@ import { BraintreePluginOptions } from './types';
  *         dropin.clearSelectedPaymentMethod();
  *   }
  * }
- *
- * ## Storing cards in the vault
- *
- * Braintree has a "vault" mechanism which allows it to store the credit card information for a Customer, so that on the next purchase
- * the stored details do not need to be re-entered.
- *
- * To enable this feature, you need to ensure that the {@link BraintreePluginOptions} `storeCustomersInBraintree` option is set to
- * `true`. This will allow Braintree to associate a unique ID to each of your Customers.
- *
- * From v1.7.0, you can then specify on a per-payment basis whether a card should be stored in the vault. By default, all cards will
- * be automatically stored in the vault. But you can opt out of this behavior by specifying the `storeCardInVault` property in the `metadata` object
- * supplied to the `addPaymentToOrder` mutation:
- *
- * @example
- * ```TypeScript {hl_lines=[21]}
- * const { addPaymentToOrder } = await graphQlClient.query(gql`
- *   mutation AddPayment($input: PaymentInput!) {
- *     addPaymentToOrder(input: $input) {
- *       ... on Order {
- *         id
- *         payments {
- *           id
- *           # ... etc
- *         }
- *       }
- *       ... on ErrorResult {
- *         errorCode
- *         message
- *       }
- *     }
- *   }`, {
- *     input: {
- *       method: 'braintree',
- *       metadata: {
- *         nonce: paymentResult.nonce,
- *         storeCardInVault: false,
- *       },
- *     },
- *   },
- * );
  * ```
- *
- *
  * @docsCategory payments-plugin
  * @docsPage BraintreePlugin
  */