Snippets Collections
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
    }

        let parameters: [String:Any] = [
            "country" : "US",
            "type" : "custom",
            "capabilities": ["card_payments": ["requested": "true"], "transfers": ["requested": "true"]]]
            //"business_type": "individual",
//            "business_profile[url]": "https://google.com"]
        
        let url = "https://api.stripe.com/v1/accounts"
        let api_key = ""
        let loginData = api_key.data(using: String.Encoding.utf8)
        let base64LoginString = loginData?.base64EncodedString()
        print("key : ", (base64LoginString ?? "") as String)
        let headers: HTTPHeaders = ["Authorization": "Basic \(base64LoginString!)", "Content-Type": "application/x-www-form-urlencoded", "Accept": "*/*"]
        AF.request(url, method: .post, parameters: parameters, headers: headers)
            .responseJSON(completionHandler: { (response) in
                do {
                    let json = try JSON(data: response.data!)
                    print(json["id"])
                }
                catch let error {
                    print(error.localizedDescription)
                }
            })
    func createStripeConnectAccount() {
        let parameters: [String:Any] = [
            "type" : "express",
            "country" : "US",
//            "capabilities": [["card_payments"]["requested"],
//            "capabilities[transfers][requested]": true,
//            "business_type": "individual",
            "business_profile[url]": "https://google.com"]
        
        let url = "https://api.stripe.com/v1/accounts"
        let api_key = "add test api key here"
        let loginData = api_key.data(using: String.Encoding.utf8)
        let base64LoginString = loginData?.base64EncodedString()
        print("key : ", (base64LoginString ?? "") as String)
        let headers: HTTPHeaders = ["Authorization": "Basic \(base64LoginString!)", "Content-Type": "application/x-www-form-urlencoded", "Accept": "*/*"]
        AF.request(url, method: .post, parameters: parameters, encoding: URLEncoding.httpBody, headers: headers)
            .responseDecodable(of: DecodableType.self)
            { response in
                switch response.result {
                case .success(let dict):
                    print("success ", response.result, dict)
                    let res = dict.id
                    print("ID1 : ", res)
                case .failure(let error):
                    print("Failure : ", error)
                }
            }
    }
star

Sun Jan 22 2023 08:20:36 GMT+0000 (Coordinated Universal Time)

#ios #swift #stripe #stripeconnect
star

Tue Apr 05 2022 07:14:32 GMT+0000 (Coordinated Universal Time)

#ios #swift #custom #stripe #stripeconnect
star

Tue Mar 29 2022 07:49:14 GMT+0000 (Coordinated Universal Time)

#ios #swift #stripe

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension