Browse Source

feat(payments-plugin): Add `includeCustomerId` metadata key to Braintree

Michael Bromley 3 years ago
parent
commit
a94fc22710

+ 6 - 1
packages/payments-plugin/src/braintree/braintree.handler.ts

@@ -41,7 +41,12 @@ export const braintreePaymentMethodHandler = new PaymentMethodHandler({
         try {
             await entityHydrator.hydrate(ctx, order, { relations: ['customer'] });
             const customer = order.customer;
-            if (options.storeCustomersInBraintree && ctx.activeUserId && customer) {
+            if (
+                options.storeCustomersInBraintree &&
+                ctx.activeUserId &&
+                customer &&
+                metadata.includeCustomerId !== false
+            ) {
                 customerId = await getBraintreeCustomerId(ctx, gateway, customer);
             }
             return processPayment(ctx, gateway, order, amount, metadata.nonce, customerId, options);

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

@@ -215,6 +215,26 @@ import { BraintreePluginOptions } from './types';
  * `, { includeCustomerId: false });
  * ```
  *
+ * as well as in the metadata of the `addPaymentToOrder` mutation:
+ *
+ * ```TypeScript
+ * const { addPaymentToOrder } = await graphQlClient.query(gql`
+ *   mutation AddPayment($input: PaymentInput!) {
+ *     addPaymentToOrder(input: $input) {
+ *       ...Order
+ *       ...ErrorResult
+ *     }
+ *   }`, {
+ *     input: {
+ *       method: 'braintree',
+ *       metadata: {
+ *         ...paymentResult,
+ *         includeCustomerId: false,
+ *       },
+ *     }
+ *   );
+ * ```
+ *
  * @docsCategory payments-plugin
  * @docsPage BraintreePlugin
  */