简体   繁体   English

使用php和swift创建托管条带帐户

[英]Create managed stripe account with php and swift

so I'm trying to create managed stripe accounts with PHP Swift and Alamofire. 因此,我尝试使用PHP Swift和Alamofire创建托管条带帐户。 But it's not working at all. 但这根本不起作用。

Here's my PHP code: 这是我的PHP代码:

  <?php

require_once('vendor/autoload.php');
\Stripe\Stripe::setApiKey("My APIKEY");

$country = $_POST['country'];

$create = \Stripe\Account::create(array(
 "country" => $country,
 "managed" => true
   )
);

?>

Here's my swift code: 这是我的快速代码:

 @IBAction func createBtn(_ sender: Any) {

        let card = STPCardParams()
        card.number = "5200828282828210"
        card.expMonth = 4
        card.expYear = 2024
        card.cvc = "242"
        card.currency = "usd"

        STPAPIClient.shared().createToken(withCard: card ,completion: {(token, error) -> Void in
            if let error = error {
                print("ERROR: \(error.localizedDescription)")
            }
            else if let token = token {
                print(token)
                self.createUsingToken(token:token)
            }
        })
    }

    func createUsingToken(token:STPToken) {
        let requestString = "My request URL"
          let params = ["token": token.tokenId, "country": "US"]

        //This line of code will suffice, but we want a response
        Alamofire.request(requestString, method: .post, parameters: params).responseJSON { (response) in
            print("REQUEST: \(response.request!)") // original URL request
            print("RESPONSE: \(response.response!)") // URL response
            print("DATA: \(response.data!)") // server data
            print("RESULT: \(response.result)") // result of response serialization
            if let JSON = response.result.error {
                print("JSON: \(JSON.localizedDescription)")
            }
        }
    }

And I'm getting this error from Alamofire: JSON: Response could not be serialized, input data was nil or zero length. 我从Alamofire收到此错误: JSON:无法序列化响应,输入数据为零或零长度。 Thanks for your help. 谢谢你的帮助。

It looks like your Swift/Alamofire request is expecting a JSON response, but your PHP code is not sending any response at all: you're sending an account creation request to Stripe but then never outputting any data. 看来您的Swift / Alamofire请求要求一个JSON响应,但是您的PHP代码根本没有发送任何响应:您正在向Stripe发送一个帐户创建请求 ,但是从不输出任何数据。

You likely want to prepare an array with the attributes that you expect in your Swift code, then output it as JSON at the end of your PHP script: 您可能希望准备一个数组,该数组具有Swift代码中期望的属性,然后在PHP脚本的末尾将其输出为JSON:

echo json_encode($result);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM