Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ApplePay] Take name and address from shippingAddress if present #275

Merged
merged 1 commit into from
Dec 1, 2015
Merged

[ApplePay] Take name and address from shippingAddress if present #275

merged 1 commit into from
Dec 1, 2015

Conversation

davidrothera
Copy link
Contributor

At present if a PKPayment object contains a shippingAddress but no billingAddress then no name/address details are extracted and passed along to Stripe.

This means that when looking on the Stripe dashboard at ApplePay charges with no billingAddress that the name/address fields are empty which is still valid.

This diff changes the behaviour so that:

  • If billingAddress and shippingAddress exist then we take the billingAddress
  • If billingAddress is set and shippingAddress is not set then we take the billingAddress
  • If shippingAddress is set and billingAddress is not set then we take the shippingAddress
  • If neither are set then we don't do anything

I tested this and checked the generated URL (from the formEncodedDataForPayment method) and checked that only one copy of the name/address data was present when both shipping & billing were set.

@@ -68,6 +68,92 @@ + (NSData *)formEncodedDataForPayment:(PKPayment *)payment {
}
}

if (payment.shippingAddress && payment.billingAddress == nil) {
NSMutableDictionary *params = [NSMutableDictionary dictionary];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of repeated code here. It'd be better to extract this into a function:

- (NSString *)queryStringWithAddress:(ABRecord *)record {
...
}

@davidrothera
Copy link
Contributor Author

Agreed @benzguo, I have changed the code now to re-use a string generator method which trims down the code a little.

@@ -21,6 +21,9 @@
*/
- (void)createTokenWithPayment:(nonnull PKPayment *)payment completion:(nonnull STPTokenCompletionBlock)completion;

// Encodes the data from an ABRecordRef (name/address) into a string. This method is used internally by STPAPIClient; you should not use it in your own code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to expose this in the header (I believe formEncodedDataForPayment was exposed for testing).

@davidrothera
Copy link
Contributor Author

  • Updated to re-use existing NSCharacterSet
  • Removed method declaration from public header

}
CFRelease(addressValues);
}
if (payment.billingAddress && payment.shippingAddress == nil) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, one more nit :)
you can consolidate this into two cases:

if (payment.billingAddress) {
    NSString *addressString = [self queryStringForAddress:payment.billingAddress characterSet:set];
    payloadString = [payloadString stringByAppendingString:addressString];
}
else if (payment.shippingAddress) {
    NSString *addressString = [self queryStringForAddress:payment.shippingAddress characterSet:set];
    payloadString = [payloadString stringByAppendingString:addressString];
}

thanks for catching and fixing this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benzguo my only reason for keeping all 3 options was so that if both the shippingAddress and the billingAddress were set then we would pick the billingAddress, doing this keeps with the same behaviour that is seen at present.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, just noticed that i'd swapped billingAddress and shippingAddress above (fixed now).

the if-else if above is equivalent to your three ifs. if both billingAddress and shippingAddress are non-nil, the first branch will be used – no need for a separate case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, amending now 👍

@0thernet
Copy link
Contributor

0thernet commented Dec 1, 2015

🎉 thanks!

0thernet added a commit that referenced this pull request Dec 1, 2015
[ApplePay] Take name and address from shippingAddress if present
@0thernet 0thernet merged commit 53f6aca into stripe:master Dec 1, 2015
davidme-stripe added a commit that referenced this pull request Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants