stripe組み入れるのは検索で以下発見したもので意外と簡単だった。
echo文でエラーになるので、この処理をどうするか実験必要。
もう少し考える必要があるようだ。
※参考サイト:https://crosspiece.jp/how-to-use-stripe/
●wp.lgs.jpでcheckout.phpが有効にならない件(2018.10.16)
libが転送されていなかった。おもてなしのもの転送したら問題なく支払いが完了した。
●URL
https://dashboard.stripe.com/login
※ログインは第2パスワードは携帯にくるタイプにしている。
●ソースコードの場所
/wp-content/themes/wp-dcafe/checkout.php
※mb_language(“English”); を「japanese」にしないと漢字が化ける。日本国内対応なら注意すること。
<?php
require_once( dirname(__FILE__).'/lib/init.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_xxx");
// Token is created using Stripe.js or Checkout!
// Get the payment token submitted by the form:
$token = $_POST['stripeToken'];
$email = $_POST['stripeEmail'];
// フォームから情報を取得:
try {
$charge = \Stripe\Charge::create(array(
"amount" => 1000,
"currency" => "usd",
"source" => $token,
"description" => "Product name",
));
}catch (\Stripe\Error\Card $e) {
// 決済できなかったときの処理
die('Settlement did not complete');
}
// Auto replay mail
mb_language("English");
mb_internal_encoding("UTF-8");
$title = "Thank you for your payment";
$msg ="Thank you for your payment.\r\n";
$msg .= "We will email you more details later.\r\n";
$msg .= "If you do not receive an automatic reply mail notification to your mail address at the time of payment, please check whether it is in junk mail.\r\n\r\n";
$msg .= "We will send you notice when your payment is confirmed .\r\n";
$msg .= "If there is no notification, please contact us from the menu 'support'.\r\n\r\n";
$msg .= "Thank you.";
$content = $msg;
$from_name = "customer center";
$from_addr = "メールアドレス";
$from_name_enc = mb_encode_mimeheader($from_name, "UTF-8");
$from = $from_name_enc . "<" . $from_addr . ">";
$header = "From: " . $from . "\n";
$header = $header . "Reply-To: " . $from;
//to user send mail
if(mb_send_mail($email,$title, $content, $header, "-f" .$from_addr)){
//echo "Email sent";
} else {
//echo "Failed to send mail";
};
// 管理者宛メール
$title_me = "Stripe report mail";
$from_me = "メールアドレス";
$content_me = "Stripe send mail report";
if(mb_send_mail($from_me,$title_me, $content_me, $header, "-f" .$from_addr)){
//echo "Email sent";
} else {
//echo "Failed to send mail";
};
// サンキューページへリダイレクト
header('Location: https://URLを書く/');
exit();
?>
●WordPressでのページに記述するコード
<form action="https://omo_welcome.com/wp-content/themes/wp-dcafe/checkout.php" method="POST"> <script src="https://checkout.stripe.com/checkout.js" class="stripe-button" data-key="pk_test_xxxxx" data-amount="1000" data-name="omowelcome" data-description="Member fee" data-image="https://stripe.com/img/documentation/checkout/marketplace.png" data-locale="usa" data-currency="usd" data-zip-code="false" data-allow-remember-me="false" data-label="Pay with Card"></script>
●試験入力
VISA
424242 424242 424242
12/23 999(ここはなんでもいいようだ)
