-
Notifications
You must be signed in to change notification settings - Fork 996
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
Conversation
@@ -68,6 +68,92 @@ + (NSData *)formEncodedDataForPayment:(PKPayment *)payment { | |||
} | |||
} | |||
|
|||
if (payment.shippingAddress && payment.billingAddress == nil) { | |||
NSMutableDictionary *params = [NSMutableDictionary dictionary]; |
There was a problem hiding this comment.
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 {
...
}
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. |
There was a problem hiding this comment.
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).
|
} | ||
CFRelease(addressValues); | ||
} | ||
if (payment.billingAddress && payment.shippingAddress == nil) { |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 if
s. if both billingAddress
and shippingAddress
are non-nil, the first branch will be used – no need for a separate case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, amending now 👍
🎉 thanks! |
[ApplePay] Take name and address from shippingAddress if present
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:
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.