Preview:
import Stripe
import Alamofire

func alertResult(_ yesPressed: Bool) {
        if yesPressed {
       
            let stripCard = STPCardParams()
            stripCard.number = "4242424242424242"
            stripCard.name = "Jane Doe"
            stripCard.cvc = "123"
            stripCard.expYear = UInt(27)
            stripCard.expMonth = UInt(12)
            
            STPAPIClient.shared.createToken(withCard: stripCard) { (token: STPToken?, error: Error?) in
                    print("Printing Strip response:\(String(describing: token?.allResponseFields))\n\n")
                    print("Printing Strip Token:\(String(describing: token?.tokenId))")
                    if error != nil {
                        print(error as Any)
                        print(error?.localizedDescription ?? "")
                    }
                
                    if let token = token {
                        print("Token:",token.tokenId)
                        //self.jdk(token: token)
                        self.handlePayment(token: token)
                    }
                }
        }
    }
    
    func handlePayment(token: STPToken) {
        let url = "https://api.stripe.com/v1/charges" + "?key=" + "paste api key here"
        
        let headers: HTTPHeaders = ["Authorization": "paste api key here", "Content-Type": "application/x-www-form-urlencoded"]
        
        let amount = Int(topUpAmountTextField.text ?? "") ?? 100
        
        let parameters: Parameters = ["amount": amount, "currency": AppDelegate.balanceType, "source": token.tokenId]
        
        AF.request(url, method: .post, parameters: parameters, headers: headers).responseDecodable(of: Charge.self) { (response) in
            print("resp : ", response)
            switch response.result {
                
            case .success(let charge):
                // Handle successful charge
                print("Success :: ", charge.status)
                print("Amount :: ", charge.amount)
                
                self.updateBalance(amount : Double(charge.amount))
                break
            case .failure(let error):
                // Handle error
                print("Failure : ", error)
                self.showToast(message: "Top-up unsuccessfull")
            }
        }
    }

    struct Charge : Decodable {
      let status : String
      let amount : Int
    }

downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter