Skip to content

Commit

Permalink
Moved recurringPaymentRequest into a method
Browse files Browse the repository at this point in the history
  • Loading branch information
stechiu committed Feb 11, 2025
1 parent 5753769 commit 5509567
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions Demo/Application/Features/ApplePayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,27 @@ 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")
self.present(paymentAuthorizationViewController, animated: true)
}
}

@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]

Expand Down

0 comments on commit 5509567

Please sign in to comment.