Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import Stripe
- class ExampleCheckoutViewController : UIViewController, STPPaymentContextDelegate {
- // MARK: Properties
- var customerContext = STPCustomerContext(keyProvider: API_Client.sharedInstance)
- var paymentContext : STPPaymentContext? = nil
- // MARK: UIViewController
- override func viewDidLoad() {
- super.viewDidLoad()
- // initialize STPPaymentContext
- // Read more: https://stripe.com/docs/mobile/ios/standard#implement-your-apps-checkout-flow-using-stppaymentcontext
- self.paymentContext = STPPaymentContext(customerContext: self.customerContext, configuration: STPPaymentConfiguration.shared(), theme: STPTheme.default())
- self.paymentContext?.delegate = self
- self.paymentContext?.hostViewController = self
- // TODO: Set an amount below
- // self.paymentContext?.paymentAmount = ??
- }
- // MARK: Button actions
- // Present payment methods view controller via Payment Context
- func buttonAPressed() {
- self.paymentContext?.presentPaymentMethodsViewController()
- }
- // Request payment via Payment Context
- func buttonBPressed() {
- self.paymentContext?.requestPayment()
- }
- // MARK: STPPaymentContextDelegate
- /* Read more: https://stripe.com/docs/mobile/ios/standard#setting-the-delegate-and-host-view-controller */
- func paymentContextDidChange(_ paymentContext: STPPaymentContext) {
- // TODO: implement
- }
- func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error) {
- // TODO: implement
- }
- func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: @escaping STPErrorBlock) {
- // TODO: Send token to server to create a charge
- }
- func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?) {
- // TODO: implement
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement