Skip to content

Commit

Permalink
Fix new STPApplePayContext result delegate method on Objective-C (#1414)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidme-stripe authored Sep 8, 2022
1 parent 673d9e0 commit f2f4e8e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
### PaymentSheet
* [Fixed] Fixed potential crash when using Link in Mac Catalyst.

### Apple Pay
* [Fixed] Fixed an issue where `applePayContext:willCompleteWithResult:authorizationResult:handler:` may not be called in Objective-C implementations of `STPApplePayContextDelegate`.

## 22.8.0 2022-09-06
### PaymentSheet
* [Changed] Renamed `PaymentSheet.reset()` to `PaymentSheet.resetCustomer()`. See `MIGRATING.md` for more info.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,18 @@ - (void)applePayContext:(STPApplePayContext *)context didSelectShippingMethod:(P
completion([[PKPaymentRequestShippingMethodUpdate alloc] initWithPaymentSummaryItems:updatedSummaryItems]);
}

- (void)applePayContext:(STPApplePayContext *)context willCompleteWithResult:(PKPaymentAuthorizationResult *)authorizationResult handler:(void (^)(PKPaymentAuthorizationResult * _Nonnull))handler {
#ifdef __IPHONE_16_0
if (@available(iOS 16.0, *)) {
authorizationResult.orderDetails = [[PKPaymentOrderDetails alloc]
initWithOrderTypeIdentifier: @"com.myapp.order"
orderIdentifier: @"ABC123-AAAA-1111"
webServiceURL: [NSURL URLWithString:@"https://my-backend.example.com/apple-order-tracking-backend"]
authenticationToken: @"abc123"];
}
#endif
handler(authorizationResult);
}


@end
17 changes: 17 additions & 0 deletions Stripe/_stpobjc_STPApplePayContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ public protocol STPApplePayContextDelegate: _stpinternal_STPApplePayContextDeleg
didSelectShippingContact contact: PKContact,
handler: @escaping (_ update: PKPaymentRequestShippingContactUpdate) -> Void
)

/// Optionally configure additional information on your PKPaymentAuthorizationResult.
/// This closure will be called after the PaymentIntent or SetupIntent is confirmed, but before
/// the Apple Pay sheet has been closed.
/// In your implementation, you can configure the PKPaymentAuthorizationResult to add custom fields, such as `orderDetails`.
/// See https://developer.apple.com/documentation/passkit/pkpaymentauthorizationresult for all configuration options.
/// This method is optional. If you implement this, you must call the handler block with the PKPaymentAuthorizationResult on the main queue.
/// WARNING: If you do not call the completion handler, your app will hang until the Apple Pay sheet times out.
@objc optional func applePayContext(
_ context: _stpobjc_APContext,
willCompleteWithResult authorizationResult: PKPaymentAuthorizationResult,
handler: @escaping (_ authorizationResult: PKPaymentAuthorizationResult) -> Void
)
}


Expand All @@ -155,6 +168,10 @@ class STPApplePayContextBridgeDelegate: NSObject, STPApplePayContextDelegate {
objcDelegate?.applePayContext?(.init(applePayContext: context), didSelectShippingContact: contact, handler: handler)
}

func applePayContext(_ context: STPApplePayContext, willCompleteWithResult authorizationResult: PKPaymentAuthorizationResult, handler: @escaping (PKPaymentAuthorizationResult) -> Void) {
objcDelegate?.applePayContext?(.init(applePayContext: context), willCompleteWithResult: authorizationResult, handler: handler)
}

/// :nodoc:
public override func responds(to aSelector: Selector!) -> Bool {
// Pass through responds(to:) so that we only respond to the shipping/contact
Expand Down

0 comments on commit f2f4e8e

Please sign in to comment.