- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
引用:
https://stripe.com/docs/sources/bitcoin
<小时/>问题:
我正在尝试使用 Stripe 将比特币支付集成到我的代码中。
根据我对文档的理解,我应该通过创建一个新表单来创建一个 Source 对象,并将数据(在本例中为电子邮件和金额)提交到:
stripe.createSource({
type: 'bitcoin',
amount: 1000,
currency: 'usd',
owner: {
email: 'jenny.rosen@example.com',
},
}).then(function(result) {
// handle result.error or result.source
});
然后将结果传递给服务器对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();
}
});
我迷路了。
这是我目前拥有的代码,非常适合美元付款。
<小时/>我的代码:
客户端( 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})
);
});
最佳答案
感谢来自 freenode IRC#stripe 的“pksk321”帮助我解决这个问题!
显然,所需要的只是将 bitcoin: true
添加到处理程序中,如下所示:
客户端
var handler = StripeCheckout.configure({
key: 'key',
locale: 'auto',
name: 'website',
description: 'Secure Payment',
bitcoin: true,
token: function(token) {
$('#stripeToken').val(token.id);
$("#stripeEmail").val(token.email);
$('form').submit();
}
});
关于javascript - 如何使用 Stripe 接受比特币和美元付款?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47891077/
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 已关闭 9 年前。 Improve
根据其他问题的列表,要构建我需要的原始交易: listunspent - 您可以获得所有未花费交易的列表 您可以决定要花哪些钱 您使用createrawtransaction来创建您的输入/输出,tx
我想查看不在我钱包中的btc地址余额。似乎像 blockchainexplorer 这样的网站会做这类事情。他们还提供 API,但我遇到了他们的 API 使用限制。所以我下载了完整的区 block 链
我的设置:在 Mongoose 模块的帮助下,我们处理所有 Mongo 数据库操作。对于每个新用户,都会生成一个钱包并将其存储在 Mongo 集合中。 方法:如果我们使用User.find({}, f
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
我正在尝试建立一个以比特币为中心的网站,并且由于主机的限制,我需要能够执行以下操作,而无需在任何服务器上运行比特币守护程序: 创建一个新的比特币地址(getnewaddress($account))
我目前正在开发一个比特币应用程序,它涉及运行一个完整的比特币节点。 当我测试我的源代码时,我决定使用比特币注册测试模式。 这是我如何启动我的比特币节点: ./bitcoind -regtest -rp
私钥是随机生成的,不与任何钱包关联。 我想为比特币准备公钥生成的自定义(简单)实现。然而,经过几次尝试,我的结果是不正确的。我将它们与在线生成器进行了比较。我发现我使用了除法而不是 modinv。不幸
我是比特币和区 block 链的新手,希望您能帮助我解决一些问题。所以我启动了一个“regtest”网络并使用 生成了 101 个 block bitcoin-cli -regtest generat
当我在我的 bitcoind 服务器上调用 getwork 时,我得到以下信息: ./bitcoind getwork { "midstate" : "695d56ae173bbd0fd5f5
我正在编写一个 JavaScript 函数来返回当前的 BTC/USD 汇率。我做了一些研究,但我只想要一些简单的东西。它不会在服务器端用于计算值(明显的安全隐患),而只是为了方便我的用户。我有 2
我正在使用 Bitrise 生成构建并将其上传到 AppStore。当我在设备上运行应用程序或生成构建并通过 Xcode 上传到 AppStore 时没有出现任何错误,但是当我尝试通过 Bitrise
我目前正在我的 Windows 7 上创建“比特币”。 我已经完成了所有必要的步骤,现在我要进行最后一部分,以获取 .exe 文件。 这是我在 QT 4.8.5 命令提示符中输入的命令 qmake U
以下链接提供有关 BTC 地址的 JSON 数据 -> https://blockchain.info/address/1GA9RVZHuEE8zm4ooMTiqLicfnvymhzRVm?forma
我是一名优秀的程序员,十分优秀!