【问题标题】:How to create STRIPE customer using STRIPE API in IOS?如何在 IOS 中使用 STRIPE API 创建 STRIPE 客户?
【发布时间】:2014-03-30 21:16:52
【问题描述】:

我的 ios 应用程序中集成了 STRIPE。

我可以使用用户输入的卡片详细信息生成令牌。

我将此 TOKEN 发送到服务器进行付款处理。

没关系!

问题,我想使用它的 API 创建一个 STRIPE 客户。

如何做到这一点,SDK是否为此提供了什么?

或者在标头中传递“Authorization_KEY”和“STRIPE_TEST_PUBLIC_KEY”是一种方式?

或者我需要为此实施整个“OAuth 2.0”?

请帮忙!

谢谢!

【问题讨论】:

  • 嗨..我在收取金额时遇到问题....我已经生成了令牌,我想通过 PARSE 收取金额是可能的..我是 iOS 的开发人员
  • @Queshi Zakir 你如何在 ios 中创建条带客户,请帮帮我。

标签: ios objective-c xcode payment-gateway stripe-payments


【解决方案1】:

我认为您不能使用公钥创建 Stripe 客户。我很确定这个请求需要密钥,所以它可能应该在服务器而不是客户端应用程序上处理。

【讨论】:

  • @QueshiZakir 您是如何将详细信息存储在条带上的?通过卡详细信息生成的令牌?你能告诉我吗,我也面临同样的问题。谢谢
【解决方案2】:

是的,nabeel 是正确的,客户应该由服务器而不是客户端应用程序创建。虽然,如果你想冒险,你可以这样做......

class StripeUtils {

    //Feed in the STPCardParams to create a Stripe token.
    func generateToken(with params: STPCardParams, completion: @escaping (Error?, STPToken?) -> ()) {

        STPAPIClient.shared().createToken(withCard: params) { (token, error) in
            completion(error, token)
        }
    }

    //Pass the token and user email address to get the STPCustomer
    func createUserWith(email: String, token: STPToken?, completion: @escaping (Error?, STPCustomer?) -> ()) {

        guard let token = token else {
            print("Token can not be nil")
            completion(*error*, nil)
            return
        }

        let headers = ["Authorization": "Bearer \(Constants.STRIPE_SECRET_KEY)"] //The secret key
        let body = ["email": email, "source": token.tokenId] as [String : Any]
        var paramString = String()

        body.forEach({ (key, value) in
            paramString = "\(paramString)\(key)=\(value)&"
        })
        let params = paramString.data(using: .utf8)

        //URLStrings.stripe_createUser is "https://api.stripe.com/v1/customers"
        //The APIManager is a class that takes urlString, params(HTTP body) and headers(HTTP headers) to get initialized.
        //(You can use Alamofire or whatever you use to handle APIs)
        //Instance of APIManager has a method called 'perform' with the URLSession's completion block  (Data?, URLResponse?, Error?) -> ()


        let manager = APIManager(urlString: URLStrings.stripe_createUser.description, params: params, headers: headers)

        manager.perform { (data, response, error) in

        //Use STPCustomerDeserializer intead of standard JSONSerialization to let Stripe hanlde the API response.

            let object = STPCustomerDeserializer.init(data: data, urlResponse: response, error: error)
            completion(object.error, object.customer)
        //That's it, you'll have a STPCustomer instance with stripeId if there were no errors.
        }
    }
}

【讨论】:

  • 我可以有上面例子的演示代码吗?因为我是条纹支付的新手,我想创建客户,需要根据客户保存卡详细信息。
  • 这是一个演示。您需要做的就是使用参数调用该 API。
猜你喜欢
  • 2023-01-18
  • 2014-11-12
  • 2015-07-03
  • 1970-01-01
  • 2016-11-20
  • 2015-12-26
  • 2018-01-01
  • 2016-09-11
  • 2019-03-28
相关资源
最近更新 更多