From 856e331ef3fe07eaf80cfe640f7a95d106842c92 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 2 Feb 2019 23:04:44 -0500 Subject: [PATCH] custom ids to braintree customers --- .../Implementations/BraintreePaymentService.cs | 13 +++++++++++-- .../Implementations/StripePaymentService.cs | 18 +++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Core/Services/Implementations/BraintreePaymentService.cs b/src/Core/Services/Implementations/BraintreePaymentService.cs index 344c7db1de..c205235fd7 100644 --- a/src/Core/Services/Implementations/BraintreePaymentService.cs +++ b/src/Core/Services/Implementations/BraintreePaymentService.cs @@ -6,6 +6,7 @@ using Braintree; using Bit.Core.Exceptions; using Bit.Core.Models.Business; using Bit.Core.Enums; +using System.Collections.Generic; namespace Bit.Core.Services { @@ -222,7 +223,11 @@ namespace Bit.Core.Services var customerResult = await _gateway.Customer.CreateAsync(new CustomerRequest { PaymentMethodNonce = paymentToken, - Email = user.Email + Email = user.Email, + CustomFields = new Dictionary + { + [user.BraintreeIdField()] = user.Id.ToString() + } }); if(!customerResult.IsSuccess() || customerResult.Target.PaymentMethods.Length == 0) @@ -336,7 +341,11 @@ namespace Bit.Core.Services var result = await _gateway.Customer.CreateAsync(new CustomerRequest { Email = subscriber.BillingEmailAddress(), - PaymentMethodNonce = paymentToken + PaymentMethodNonce = paymentToken, + CustomFields = new Dictionary + { + [subscriber.BraintreeIdField()] = subscriber.Id.ToString() + } }); if(!result.IsSuccess()) diff --git a/src/Core/Services/Implementations/StripePaymentService.cs b/src/Core/Services/Implementations/StripePaymentService.cs index 007abcd86a..501deb46fe 100644 --- a/src/Core/Services/Implementations/StripePaymentService.cs +++ b/src/Core/Services/Implementations/StripePaymentService.cs @@ -54,7 +54,11 @@ namespace Bit.Core.Services { PaymentMethodNonce = paymentToken, Email = org.BillingEmail, - Id = org.BraintreeCustomerIdPrefix() + org.Id.ToString("N").ToLower() + randomSuffix + Id = org.BraintreeCustomerIdPrefix() + org.Id.ToString("N").ToLower() + randomSuffix, + CustomFields = new Dictionary + { + [org.BraintreeIdField()] = org.Id.ToString() + } }); if(!customerResult.IsSuccess() || customerResult.Target.PaymentMethods.Length == 0) @@ -174,7 +178,11 @@ namespace Bit.Core.Services { PaymentMethodNonce = paymentToken, Email = user.Email, - Id = user.BraintreeCustomerIdPrefix() + user.Id.ToString("N").ToLower() + randomSuffix + Id = user.BraintreeCustomerIdPrefix() + user.Id.ToString("N").ToLower() + randomSuffix, + CustomFields = new Dictionary + { + [user.BraintreeIdField()] = user.Id.ToString() + } }); if(!customerResult.IsSuccess() || customerResult.Target.PaymentMethods.Length == 0) @@ -767,7 +775,11 @@ namespace Bit.Core.Services PaymentMethodNonce = paymentToken, Email = subscriber.BillingEmailAddress(), Id = subscriber.BraintreeCustomerIdPrefix() + subscriber.Id.ToString("N").ToLower() + - Utilities.CoreHelpers.RandomString(3, upper: false, numeric: false) + Utilities.CoreHelpers.RandomString(3, upper: false, numeric: false), + CustomFields = new Dictionary + { + [subscriber.BraintreeIdField()] = subscriber.Id.ToString() + } }); if(!customerResult.IsSuccess() || customerResult.Target.PaymentMethods.Length == 0)