Advertisement
hmunoz-stripe

STPPaymentContext setup

Jan 25th, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.98 KB | None | 0 0
  1. import UIKit
  2. import Stripe
  3.  
  4. class ExampleCheckoutViewController : UIViewController, STPPaymentContextDelegate {
  5.    
  6.     // MARK: Properties
  7.     var customerContext = STPCustomerContext(keyProvider: API_Client.sharedInstance)
  8.     var paymentContext : STPPaymentContext? = nil
  9.    
  10.     // MARK: UIViewController
  11.  
  12.     override func viewDidLoad() {
  13.         super.viewDidLoad()
  14.        
  15.         // initialize STPPaymentContext
  16.         // Read more: https://stripe.com/docs/mobile/ios/standard#implement-your-apps-checkout-flow-using-stppaymentcontext
  17.         self.paymentContext = STPPaymentContext(customerContext: self.customerContext, configuration: STPPaymentConfiguration.shared(), theme: STPTheme.default())
  18.         self.paymentContext?.delegate = self
  19.         self.paymentContext?.hostViewController = self
  20.        
  21.         // TODO: Set an amount below
  22.         // self.paymentContext?.paymentAmount = ??
  23.     }
  24.    
  25.     // MARK: Button actions
  26.  
  27.     // Present payment methods view controller via Payment Context
  28.     func buttonAPressed() {
  29.         self.paymentContext?.presentPaymentMethodsViewController()
  30.     }
  31.    
  32.     // Request payment via Payment Context
  33.     func buttonBPressed() {
  34.         self.paymentContext?.requestPayment()
  35.     }
  36.    
  37.     // MARK: STPPaymentContextDelegate
  38.     /* Read more: https://stripe.com/docs/mobile/ios/standard#setting-the-delegate-and-host-view-controller */
  39.  
  40.     func paymentContextDidChange(_ paymentContext: STPPaymentContext) {
  41.         // TODO: implement
  42.     }
  43.    
  44.     func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error) {
  45.         // TODO: implement
  46.     }
  47.    
  48.     func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: @escaping STPErrorBlock) {
  49.         // TODO: Send token to server to create a charge
  50.     }
  51.    
  52.     func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?) {
  53.         // TODO: implement
  54.     }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement