Closed DwieDima closed 3 years ago
Hi @DwieDima, I'm having trouble replicating this issue -- the billing address fields are not coming back as null for me. Could you share your code for creating the billing address?
Also, you mentioned that you're looking at the values inside billing
, but I assume you mean response.paymentMethod.billingAddress
? There is no billing
field on paymentMethod
.
Hi @sestevens.
my workflow is:
const braintreeUser = await gateway.customer.create({
firstName: user.firstName,
lastName: user.lastName,
email: user.email
});
await gateway.address.create({
customerId: braintreeUser.customer.id,
firstName: user.firstName,
lastName: user.lastName,
streetAddress: user.address.street + " " + user.address.houseNumber,
locality: user.address.city,
postalCode: user.address.postalCode,
countryCodeAlpha2: user.address.country.code
});
public addCreditCard() {
this.isLoading = true;
this.hostedFieldsInstance.tokenize(
{
vault: true,
},
(tokenizeErr, payload) => {
if (tokenizeErr) {
console.log('tokenizeErr', tokenizeErr);
this.isLoading = false;
// this shows an error alert message
this.onAddPaymentError();
} else {
console.log('nonce', payload);
// this sends the payload none to my backend where i save the payment method
this.savePaymentMethodAndDismissModal(payload.nonce).toPromise();
}
}
);
}
// link the addressId created on user registration
return gateway.paymentMethod
.create({
customerId: userData.braintreeCustomerId,
billingAddressId: userData.braintreeAddressId,
paymentMethodNonce
});
When i log the response of paymentMethod.create() i get the same response as i mentioned at the beginning (success: true, billingAddress fields null).
---UPDATE---
Now i added the user address on the clientside, too (step 3) and it works as expected:
public addCreditCard() {
const user = this.userService.getCurrentUser();
this.isLoading = true;
this.hostedFieldsInstance.tokenize(
{
vault: true,
billingAddress: {
firstName: user.firstName,
lastName: user.lastName,
streetAddress: user.address.street + ' ' + user.address.houseNumber,
locality: user.address.city,
postalCode: user.address.postalCode,
countryCodeAlpha2: user.address.country.code,
},
},
(tokenizeErr, payload) => {
if (tokenizeErr) {
console.log('tokenizeErr', tokenizeErr);
this.isLoading = false;
this.onAddPaymentError();
} else {
console.log('nonce', payload);
this.savePaymentMethodAndDismissModal(payload.nonce).toPromise();
}
}
);
}
is this behavior intended so that if you do not specify the billingAddress on the client side, the addressBillingId is not taken into account on the backend side in paymentMethod.create()?
@DwieDima Yes, this is expected behavior. Since you're passing vault: true
on the client, the payment method is created with the information (such as billing address) that you provide. When you call paymentMethod.create
on the server with payment method nonce that you vaulted on the client, it doesn't create a new payment method. Instead, it just returns the existing payment method with whatever information was originally provided on the client.
There are two options here:
vault: true
, without passing a billing address, you need to call paymentMethod.update
on the server to add the billing address (not paymentMethod.create
).vault: true
on the client. Then you would call paymentMethod.create
on the server and pass in the billing address.Feel free to reach out to Braintree Support with any further questions!
@sestevens thank you for clarification!
General information
Issue description
creating a payment method with existing
billingAddressId
not working. All values insidebilling
ofpaymentmethod
isnull
.this is the method i call:
this is the billing response object:
the
success
response object istrue
.This Address is working on the customer object.