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

Add support for apple pay coupons. #3280

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ import PassKit
handler: @escaping (_ update: PKPaymentRequestShippingContactUpdate) -> Void
)

/// Called when the user has entered a coupon code. You should validate the
/// coupon and must invoke the completion block with a PKPaymentRequestCouponCodeUpdate object.
@available(iOS 15.0, *)
@objc optional func applePayContext(
_ context: STPApplePayContext,
didChangeCouponCode couponCode: String,
handler completion: @escaping (PKPaymentRequestCouponCodeUpdate) -> 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.
Expand Down Expand Up @@ -305,11 +314,32 @@ public class STPApplePayContext: NSObject, PKPaymentAuthorizationControllerDeleg
didSelectShippingContact:
handler:
))

return [
var delegateToAppleDelegateMapping = [
pk_didSelectShippingMethod: stp_didSelectShippingMethod,
pk_didSelectShippingContact: stp_didSelectShippingContact,
]

if #available(iOS 15.0, *) {
// On iOS 15+, Apple Pay can now accept coupon codes directly, so we need to broker the
// new coupon delegate functions between the host app and Apple Pay.
let pk_didChangeCouponCode = #selector(
PKPaymentAuthorizationControllerDelegate.paymentAuthorizationController(
_:
didChangeCouponCode:
handler:
))
let stp_didChangeCouponCode = #selector(
_stpinternal_STPApplePayContextDelegateBase.applePayContext(
_:
didChangeCouponCode:
handler:
))

delegateToAppleDelegateMapping[pk_didChangeCouponCode] = stp_didChangeCouponCode
}

return delegateToAppleDelegateMapping
}

func _end() {
Expand Down Expand Up @@ -427,6 +457,22 @@ public class STPApplePayContext: NSObject, PKPaymentAuthorizationControllerDeleg
}
}

/// :nodoc:
@available(iOS 15.0, *)
@objc
public func paymentAuthorizationController(
_ controller: PKPaymentAuthorizationController,
didChangeCouponCode couponCode: String,
handler completion: @escaping (PKPaymentRequestCouponCodeUpdate) -> Void) {

if delegate?.responds(
to: #selector(
_stpinternal_STPApplePayContextDelegateBase.applePayContext(_:didChangeCouponCode:handler:))
) ?? false {
delegate?.applePayContext?(self, didChangeCouponCode: couponCode, handler: completion)
}
}

/// :nodoc:
@objc public func paymentAuthorizationControllerDidFinish(
_ controller: PKPaymentAuthorizationController
Expand Down