PayPal Live 決済テスト
<div id="paypal-button-container"></div>
<script src="https://www.paypal.com/sdk/js?client-id=YOUR_LIVE_CLIENT_ID¤cy=JPY" data-sdk-integration-source="integrationbuilder"></script>
<script>
// 2. 決済ボタンのレンダリング
paypal.Buttons({
// 注文作成時の設定 (商品情報や金額の設定)
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '10.00', // テスト用に10円を設定(Liveなので実際の日本円)
currency_code: 'JPY'
}
}]
});
},
// 決済実行時の設定
onApprove: function(data, actions) {
return actions.order.capture().then(function(orderData) {
// 決済が成功したら、アラートで通知
alert('決済が成功しました! 注文ID: ' + orderData.id);
// 成功後の処理(データベースへの記録など)は、通常サーバー側で行います。
});
},
// エラー発生時の設定
onError: function(err) {
console.error('PayPal エラー:', err);
alert('決済処理中にエラーが発生しました。コンソールを確認してください。');
}
}).render('#paypal-button-container'); // 'paypal-button-container' にボタンを表示
</script>