REFERENCE:ストライプを使用してBitcoinとUSDの支払いを受け入れる方法は?
https://stripe.com/docs/sources/bitcoin
QUESTION:
私はストライプを使用して私のコードにビットコインの支払いを統合しようとしています。
ドキュメントの私の理解から、私は新しいフォームを作成することによって、ソースオブジェクトを作成し、上への供給に(この場合は電子メールおよび量で)データを提出する必要があります
stripe.createSource({
type: 'bitcoin',
amount: 1000,
currency: 'usd',
owner: {
email: '[email protected]',
},
}).then(function(result) {
// handle result.error or result.source
});
その後に結果を渡しますソースオブジェクトを請求するサーバー。問題のみ:結果をサーバーに渡す方法はわかりません。新しいハンドラを作成する必要がありますか?
var handler = StripeCheckout.configure({
key: 'key',
locale: 'auto',
name: 'website',
description: 'Secure Payment',
token: function(token) {
$('#stripeToken').val(token.id);
$("#stripeEmail").val(token.email);
$('form').submit();
}
});
私は迷っています。
ここに私が現在持っているコードは、USD支払いのために完全に機能します。
MY CODE:
クライアント側(payment.ejs)
<% include partials/header %>
<div class="background">
<div class="message">
<div class="paymentBlock">
<h1 class="title">TITLE</h1>
<form class="paymentForm" action="/payment/charge" method="POST">
<input id="inputAmount" class="amountInput" name="amount" type="number/>
<input type="hidden" id="stripeToken" name="stripeToken" />
<input type="hidden" id="stripeEmail" name="stripeEmail"/>
<button type="submit" class="btn btn-success" id="paymentButton" >Submit Payment</button>
</form>
</div>
</div>
</div>
<script src="https://checkout.stripe.com/checkout.js"></script>
<script>
var handler = StripeCheckout.configure({
key: 'key',
locale: 'auto',
name: 'website',
description: 'Secure Payment',
token: function(token) {
$('#stripeToken').val(token.id);
$("#stripeEmail").val(token.email);
$('form').submit();
}
});
$('#paymentButton').on('click', function(e) {
e.preventDefault();
$('#error_explanation').html('');
var amount = $('#inputAmount').val();
amount = amount.replace(/\$/g, '').replace(/\,/g, '');
amount = parseFloat(amount);
if (isNaN(amount)) {
$('#error_explanation').html('<p>Please enter a valid amount in USD ($).</p>');
}
else if (amount < 1.00) {
$('#error_explanation').html('<p>Payment amount must be at least $1.</p>');
}
else {
amount = amount * 100;
handler.open({
amount: Math.round(amount)
})
}
});
// Close Checkout on page navigation
$(window).on('popstate', function() {
handler.close();
});
</script>
<% include partials/indexScripts %>
サーバーサイド(payment.js)
router.post("/", (req, res) => {
var amount = req.body.amount;
var object;
var ARef = admin.database().ref("ref");
var ARefList;
amount = amount * 100;
var object = {
amount: amount,
email: email,
inversedTimeStamp: now
}
stripe.customers.create({
email: req.body.stripeEmail,
source: req.body.stripeToken
})
.then(customer =>
stripe.charges.create({
amount: amount,
description: "desc",
currency: "usd",
customer: customer.id
})
)
.then(charge =>
ARef.transaction(function(dbAmount){
if (!dbAmount) {
dbAmount = 0;
}
dbAmount = dbAmount + amount/100;
return dbAmount;
})
)
.then(() =>
ARef.push(object)
)
.then (() =>
ARefList.push(object)
)
.then(() =>
res.render("received",{amount:amount/100})
);
});
あなたの質問のセクションでは、質問が含まれていません! 「苦労する」と定義する。これは無意味な文章ほど曖昧です。それであなたの状況については何も推測できません。上のコードで何が問題になっていますか? https://stackoverflow.com/help/how-to-askを参照して質問を明確にしてください。 – ADyson
あなたのHTMLは気にしません。つまり、フロントエンドを構築する上でのあなたの役割です。あなたがAPIに苦労している場合、それはあなたの質問に集中しなければならないもので、無関係の情報は入れないでください –
あなたは何について明確ではありませんか? –