私はStripeとPayPalを使用するアプリを作成しました。トークンを取得するために、XAMPPを使用してMac上にローカルバックエンドサーバーを作成しました。スウィフトモバイルアプリのバックエンドとしての外部サーバー
//です。 。 。 HTTPのPOSTリクエスト
func postStripeToken(token: STPToken) {
let URL = "http://localhost/ryde/payment.php"
let params = ["stripeToken": token.tokenId,
"amount": Double(self.driverInfoView.rydeFare.text!)!,
"currency": "cad",
"description": self.riderName] as [String : Any]
let manager = AFHTTPSessionManager()
manager.post(URL, parameters: params, success: { (operation, responseObject) -> Void in
if let response = responseObject as? [String: String] {
let alertController = UIAlertController(title: response["status"], message: response["message"], preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)
}
}) { (operation, error) -> Void in
self.handleError(error as NSError)
print(error)
}
}
payment.php
<?php
require_once('vendor/autoload.php');
// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("sk_test_**********************");
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
$amount = $_POST['amount'];
$currency = $_POST['currency'];
// $description = $_POST['description'];
// Create the charge on Stripe's servers - this will charge the user's card
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
}
?>
は、問題は、私は、ローカルサーバーを使用している場合、私はいつもXAMPPを持っている必要がありますということであることによって、私たちのバックエンドにトークンを送ります実行しているので、モバイルアプリケーションに何も問題はありません。
ローカルバックエンドではなく外部バックエンドを作成するにはどうすればよいですか?
ご協力いただければ幸いです。
たとえば、Herokuのようなコードを使用してコードをオンラインにしたいとします。https://www.heroku.com/ – koopajah
私はHerokuのアカウントを設定しています。このコードを実装する方法を教えてください。 – LizG
コードをすでに作成しています。あなたはherokuに展開する必要があります。チュートリアルでは、そこに到達するのを手伝うことができます。それ以外の場合は、サポートチームに連絡することをお勧めします。これはStackOverflowの対象外です。 – koopajah