Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import Stripe
- class PaymentContextViewController: UIViewController, STPPaymentContextDelegate {
- //MARK: Properties
- var customerContext = STPCustomerContext(keyProvider: API_Client.sharedInstance)
- var paymentContext : STPPaymentContext? = nil
- //MARK: Setup
- override func viewDidLoad() {
- super.viewDidLoad()
- self.paymentContext = STPPaymentContext(customerContext: self.customerContext, configuration: STPPaymentConfiguration.shared(), theme: STPTheme.default())
- self.paymentContext?.delegate = self
- self.paymentContext?.hostViewController = self
- self.paymentContext?.paymentAmount = 4999
- }
- //MARK: IBActions
- @IBAction func paymentMethodsButtonPressed(_ sender: Any) {
- self.paymentContext?.pushPaymentMethodsViewController()
- }
- @IBAction func requestPaymentPressed(_ sender: Any) {
- self.paymentContext?.requestPayment()
- }
- //MARK: PaymentContextDelegate
- func paymentContextDidChange(_ paymentContext: STPPaymentContext) {
- }
- func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error) {
- }
- func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: @escaping STPErrorBlock) {
- API_Client.sharedInstance.completeCharge(paymentResult, amount: 1234, shippingAddress: nil, shippingMethod: nil, completion: completion)
- }
- func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement