[英]Create managed stripe account with php and swift
因此,我嘗試使用PHP Swift和Alamofire創建托管條帶帳戶。 但這根本不起作用。
這是我的PHP代碼:
<?php
require_once('vendor/autoload.php');
\Stripe\Stripe::setApiKey("My APIKEY");
$country = $_POST['country'];
$create = \Stripe\Account::create(array(
"country" => $country,
"managed" => true
)
);
?>
這是我的快速代碼:
@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)")
}
}
}
我從Alamofire收到此錯誤: JSON:無法序列化響應,輸入數據為零或零長度。 謝謝你的幫助。
看來您的Swift / Alamofire請求要求一個JSON響應,但是您的PHP代碼根本沒有發送任何響應:您正在向Stripe發送一個帳戶創建請求 ,但是從不輸出任何數據。
您可能希望准備一個數組,該數組具有Swift代碼中期望的屬性,然后在PHP腳本的末尾將其輸出為JSON:
echo json_encode($result);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.