1
確定經過多次搜索後,我不知道這是怎麼回事,因爲我認爲我在更換密鑰時工作正常。然而,它不再工作,我什麼都沒有改變。不要報告重複,請不要回答任何問題。數據無法被讀取,因爲它的格式不正確
let URL = "http://localhost/donate/payment.php"
let params: Dictionary<String,AnyObject> = ["stripeToken": token.tokenId,
"amount": Int(self.amountTextField.text!)!,
"currency": "usd",
"description": self.emailTextField.text!]
let manager = AFHTTPSessionManager()
manager.responseSerializer.acceptableContentTypes = NSSet(array: ["text/plain", "text/html", "application/json"]) as! Set<String>
manager.PATCH(URL, parameters: params, success: { (operation, responseObject) -> Void in
guard let response = responseObject as? [String: String] else {
print("failed")
return
}
}) { (operation, error) -> Void in
self.handleError(error)
}
這裏是我的PHP代碼,我從appcoda了(我從來沒有在PHP編碼)
<?php
require_once('vendor/autoload.php');
\Stripe\Stripe::setApiKey("key");
$token = $_POST['stripeToken'];
$amount = $_POST['amount'];
$currency = $_POST['currency'];
$description = $_POST['description'];
try {
$charge = \Stripe\Charge::create(array(
"amount" => $amount*100, // Convert amount in cents to dollar
"currency" => $currency,
"source" => $token,
"description" => $description)
);
// Check that it was paid:
if ($charge->paid == true) {
$response = array('status'=> 'Success', 'message'=>'Payment has been charged!!');
} else { // Charge was not paid!
$response = array('status'=> 'Failure', 'message'=>'Your payment could NOT be processed because the payment system rejected the transaction. You can try again or use another card.');
}
header('Content-Type: application/json');
echo json_encode($response);
} catch(\Stripe\Error\Card $e) {
// The card has been declined
}
?>
爲什麼你使用'PATCH'方法使用'POST'而不是 –
已過時iOS 9的帖子 – mn1
@HamzaAnsari我想這是問題所在。你想將它作爲答案發布,以便我可以選擇它作爲正確的答案。如果你還可以解釋爲什麼補丁不是很好的方法。謝謝 – mn1