Advertisement
hmunoz-stripe

Untitled

Jan 9th, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.62 KB | None | 0 0
  1. import UIKit
  2. import Stripe
  3.  
  4. class PaymentContextViewController: UIViewController, STPPaymentContextDelegate {
  5.  
  6.     //MARK: Properties
  7.  
  8.     var customerContext = STPCustomerContext(keyProvider: API_Client.sharedInstance)
  9.     var paymentContext : STPPaymentContext? = nil
  10.  
  11.     //MARK: Setup
  12.  
  13.     override func viewDidLoad() {
  14.         super.viewDidLoad()
  15.        
  16.         self.paymentContext = STPPaymentContext(customerContext: self.customerContext, configuration: STPPaymentConfiguration.shared(), theme: STPTheme.default())
  17.         self.paymentContext?.delegate = self
  18.         self.paymentContext?.hostViewController = self
  19.         self.paymentContext?.paymentAmount = 4999
  20.     }
  21.  
  22.     //MARK: IBActions
  23.  
  24.     @IBAction func paymentMethodsButtonPressed(_ sender: Any) {
  25.         self.paymentContext?.pushPaymentMethodsViewController()
  26.     }
  27.    
  28.     @IBAction func requestPaymentPressed(_ sender: Any) {
  29.         self.paymentContext?.requestPayment()
  30.     }
  31.  
  32.     //MARK: PaymentContextDelegate
  33.  
  34.     func paymentContextDidChange(_ paymentContext: STPPaymentContext) {
  35.     }
  36.    
  37.     func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error) {
  38.     }
  39.    
  40.     func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: @escaping STPErrorBlock) {
  41.         API_Client.sharedInstance.completeCharge(paymentResult, amount: 1234, shippingAddress: nil, shippingMethod: nil, completion: completion)
  42.     }
  43.    
  44.     func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?) {
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement