add standalone shipping address view controller
This commit is contained in:
parent
4100525890
commit
a157132074
|
@ -13,7 +13,7 @@ class CheckoutViewController: UIViewController, STPPaymentContextDelegate, STPSh
|
|||
|
||||
// 1) To get started with this demo, first head to https://dashboard.stripe.com/account/apikeys
|
||||
// and copy your "Test Publishable Key" (it looks like pk_test_abcdef) into the line below.
|
||||
let stripePublishableKey = ""
|
||||
let stripePublishableKey = "pk_test_DhW2G4j13BMRIC7gd55hZeW3"
|
||||
|
||||
// 2) Next, optionally, to have this demo save your user's payment details, head to
|
||||
// https://github.com/stripe/example-ios-backend , click "Deploy to Heroku", and follow
|
||||
|
@ -23,7 +23,7 @@ class CheckoutViewController: UIViewController, STPPaymentContextDelegate, STPSh
|
|||
|
||||
// 3) Optionally, to enable Apple Pay, follow the instructions at https://stripe.com/docs/mobile/apple-pay
|
||||
// to create an Apple Merchant ID. Replace nil on the line below with it (it looks like merchant.com.yourappname).
|
||||
let appleMerchantID: String? = nil
|
||||
let appleMerchantID: String? = "foo"
|
||||
|
||||
// These values will be shown to the user when they purchase with Apple Pay.
|
||||
let companyName = "Emoji Apparel"
|
||||
|
@ -259,4 +259,36 @@ class CheckoutViewController: UIViewController, STPPaymentContextDelegate, STPSh
|
|||
self.shippingVC.dismiss(completion: nil)
|
||||
}
|
||||
|
||||
// MARK: STPShippingAddressViewControllerDelegate
|
||||
|
||||
func shippingAddressViewControllerDidCancel(addressViewController: STPShippingAddressViewController) {
|
||||
let _ = self.navigationController?.popViewController(animated: true)
|
||||
}
|
||||
|
||||
func shippingAddressViewController(addressViewController: STPShippingAddressViewController, didEnterAddress address: STPAddress, completion: @escaping STPShippingMethodsCompletionBlock) {
|
||||
let shippingMethod1 = PKShippingMethod()
|
||||
shippingMethod1.amount = 0
|
||||
shippingMethod1.label = "UPS Ground"
|
||||
shippingMethod1.detail = "Arrives in 3-5 days"
|
||||
shippingMethod1.identifier = "123"
|
||||
let shippingMethod2 = PKShippingMethod()
|
||||
shippingMethod2.amount = 5.99
|
||||
shippingMethod2.label = "FedEx"
|
||||
shippingMethod2.detail = "Arrives tomorrow"
|
||||
shippingMethod2.identifier = "456"
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
||||
completion(nil, [shippingMethod1, shippingMethod2])
|
||||
}
|
||||
}
|
||||
|
||||
func shippingAddressViewController(addressViewController: STPShippingAddressViewController, didFinishWithAddress address: STPAddress, shippingMethod method: PKShippingMethod?) {
|
||||
if let shippingMethod = method {
|
||||
self.shippingRow.detail = shippingMethod.label
|
||||
}
|
||||
else {
|
||||
self.shippingRow.detail = "Enter \(self.shippingString) Info"
|
||||
}
|
||||
self.shippingVC.dismiss(withHostViewController: self)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue