From 550956777bf815cad78fbbd61952cb265739c9e4 Mon Sep 17 00:00:00 2001 From: stechiu Date: Tue, 11 Feb 2025 14:28:34 -0800 Subject: [PATCH] Moved `recurringPaymentRequest` into a method --- .../Features/ApplePayViewController.swift | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Demo/Application/Features/ApplePayViewController.swift b/Demo/Application/Features/ApplePayViewController.swift index ae48e285d..96e585b67 100644 --- a/Demo/Application/Features/ApplePayViewController.swift +++ b/Demo/Application/Features/ApplePayViewController.swift @@ -40,15 +40,8 @@ class ApplePayViewController: PaymentButtonBaseViewController { let paymentAuthorizationViewController = PKPaymentAuthorizationViewController(paymentRequest: paymentRequest)! paymentAuthorizationViewController.delegate = self - guard let managementURL = URL(string: "https://www.merchant.com/update-payment") else { return } - - if #available(iOS 16, *) { - let recurringPaymentRequest = PKRecurringPaymentRequest( - paymentDescription: "Payment description.", - regularBilling: PKRecurringPaymentSummaryItem(label: "Payment label", amount: 10.99), - managementURL: managementURL - ) - paymentRequest.recurringPaymentRequest = recurringPaymentRequest + if #available(iOS 16.0, *) { + paymentRequest.recurringPaymentRequest = self.recurringPaymentRequest() } self.progressBlock("Presenting Apple Pay Sheet") @@ -56,6 +49,18 @@ class ApplePayViewController: PaymentButtonBaseViewController { } } + @available(iOS 16.0, *) + private func recurringPaymentRequest() -> PKRecurringPaymentRequest { + let managementURL = URL(string: "https://www.merchant.com/update-payment")! + + let recurringPaymentRequest = PKRecurringPaymentRequest( + paymentDescription: "Payment description.", + regularBilling: PKRecurringPaymentSummaryItem(label: "Payment label", amount: 10.99), + managementURL: managementURL + ) + return recurringPaymentRequest + } + private func constructPaymentRequest(with paymentRequest: PKPaymentRequest) -> PKPaymentRequest { paymentRequest.requiredBillingContactFields = [PKContactField.name]