Reputation: 4306
I am using brain-tree as payment gateway. In that i am using drop-in UI. in drop-in ui there is a option change payment method. When i do the change payment method, its getting changed but its not getting to set default. And for next transaction its taking old card only not newly added card.
my 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>
i am not getting how to set the payment method to default when added new card. Help will be appreciated. Thank you.
Upvotes: 1
Views: 3620
Reputation: 71
Add the defaultFirst
option to the braintree.setup
and your set default payment method will be automatically selected and show in the drop-in UI.
braintree.setup("{{ client_token }}", "dropin", {
container: "checkout",
form: "checkoutForm",
defaultFirst: true
});
Feature added in braintree JS v2.24.0
Documentation: https://developers.braintreepayments.com/reference/client-reference/javascript/v2/configuration#setup-method-options
Source: https://github.com/braintree/braintree-web/issues/76#issuecomment-244162120
Upvotes: 1
Reputation: 312
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
There are some things worth noting about setting the default payment method.
Hopefully that helps
Upvotes: 1
Reputation: 4306
i Solved this issue by deleting the payment method immediate after failed or successful transaction.
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
as it was one time payment, it did not affected much by deleting the user payment method. In transaction anyway i can see the details. Hope this will help some one.
Upvotes: 0