[英]set change payment method to default braintree drop-in ui
我正在使用Brain-tree作為支付網關。 在這種情況下,我正在使用嵌入式UI。 在下拉式用戶界面中,有一個選項更改付款方式。 當我執行更改付款方式時,其更改了,但是沒有設置默認值。 對於下一次交易,其取用的舊卡僅不是新添加的卡。
我的js
<script>
$(document).ready(function() {
braintree.setup("{{ client_token }}", "dropin", {
container: "checkout",
form: "checkoutForm"
});
$("#submitPayment").on("click", function () {
$("button").off("click");
$("a").off("click");
$('body').off("click");
var btn = $(this).button("loading")
setTimeout(function () {
btn.button('reset');
}, 3500)
});
});
</script>
form.html
<form id='checkoutForm' method='POST' action="/upgrade/">{% csrf_token %}
<div id='checkout' ></div>
<input type="hidden" name="plan" value="{{ plan }}"/>
<input name="token" type="hidden" value="{{ client_token }}" />
<!-- disable this when clicked -->
<button type="button" class="btn modal-action modal-close right margin-class canceleledd"
style="display:none;background-color:lightcoral;color: #000000;">Cancel</button>
<input id='submitPayment' type='submit' data-loading-text="Completing..." class='btn right margin-class' value='Pay ${{ amount }}' autocomplete="off" style="background-color:lightblue;color: #000000;"/>
</form>
添加新卡時,我不知道如何將付款方式設置為默認。 幫助將不勝感激。 謝謝。
全面披露:我在Braintree工作。 如果您還有其他疑問,請隨時與支持小組聯系。
設置默認付款方式需要注意一些事項。
希望有幫助
將defaultFirst
選項添加到braintree.setup
,您設置的默認付款方式將被自動選擇並顯示在下拉式用戶界面中。
braintree.setup("{{ client_token }}", "dropin", {
container: "checkout",
form: "checkoutForm",
defaultFirst: true
});
在Braintree JS v2.24.0中添加的功能
文檔: https : //developers.braintreepayments.com/reference/client-reference/javascript/v2/configuration#setup-method-options
來源: https : //github.com/braintree/braintree-web/issues/76#issuecomment-244162120
i解決了此問題,方法是在交易失敗或成功后立即刪除付款方式。
views.py
payment_method_result = braintree.Transaction.sale({
"customer_id": merchant_customer_id,
"amount": am,
"options": {
"submit_for_settlement": True
}
})
# print dir(payment_method_result.transaction)
# print payment_method_result
# print payment_method_result.transaction
try:
result = braintree.PaymentMethod.delete(payment_method_result.transaction.credit_card['token'])
except:
pass
由於是一次付款,因此刪除用戶付款方式並沒有太大影響。 無論如何,在交易中我可以看到詳細信息。 希望這會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.