다음보기는 자바 스크립트 코드의 경고에서 알 수있는 적절한 임시 값을 생성합니다.
<div class='row'>
<div class='small-12 columns text-center'>
<h4><%= t('proceed_to_payment') %> <%= number_to_currency(@clientorder.payment_amount) %></h4>
<% if [email protected]? %>
<%= form_tag transacted_clientorders_path(id: @clientorder.id), id: 'checkout' do %>
<input type="hidden" id="nonce" name="payment_method_nonce" />
<div id='dropin-container'></div>
<%= submit_tag t('submit'), id: 'submit-button' %>
<% end %>
<script>
$.ajax({
method: "POST",
url: "/transacted?id=<%= @clientorder.id %>&locale=<%= I18n.locale %>",
data: { payment_method_nonce: payload.nonce }
})
</script>
<script>
var button = document.querySelector('#submit-button');
braintree.dropin.create({
authorization: "<%= @client_token %>",
container: '#dropin-container'
}, function (createErr, instance) {
button.addEventListener('click', function () {
instance.requestPaymentMethod(function (err, payload) {
alert(payload.nonce);
console.log(payload.nonce);
console.log(err);
if (err) {
console.log('Error', err);
return;
}
// Add the nonce to the form and submit
document.querySelector('#nonce').value = payload.nonce;
form.submit();
});
});
});
</script>
<% end %>
</div>
</div>
컨트롤러 액션
def transacted
@result = Braintree::Transaction.sale(
amount: @clientorder.payment_amount,
payment_method_nonce: params[:payment_method_nonce],
options: {
submit_for_settlement: true},
)
if @result.transaction.status == "submitted_for_settlement"
[...]
그러나 추가 조치로 이어지지는 않습니다. @result
nonce가 제출되지 않았기 때문에 nil이며 실제로 다음을 위해 전달되지 않은 금액도 기록 된 요청 매개 변수입니다.
{"utf8"=>"✓",
"authenticity_token"=>"qXjwFuI4mNRM+ZFoQ5TwvUBv58fLNVJyQVHJm/FfBdIaArbfhjJP0WirTe+7FnSl+/asJ+fY+d+JPA7xKNLP6Q==",
"payment_method_nonce"=>"",
"commit"=>"Submit",
"id"=>"4",
"locale"=>"en"}
이것이 적절한 경로에서 벗어난 곳은 어디입니까?
몇 가지 잘못된 점이 있습니다.
!result.success?
되므로 해시 result.errors
가 결국 처리되어야합니다.그러므로,
<div class='row'>
<div class='small-12 columns text-center'>
<div id="dropin-container"></div>
<button id="submit-button" class='button success'><%= t('proceed_to_payment') %> <%= number_to_currency(@clientorder.payment_amount) %></button>
<script>
var button = document.querySelector('#submit-button');
braintree.dropin.create({
authorization: '<%= @client_token %>',
container: '#dropin-container'
}, function (createErr, instance) {
button.addEventListener('click', function () {
instance.requestPaymentMethod(function (err, payload) {
// Submit payload.nonce to your server
$.ajax({
method: "POST",
url: "<%= transacted_clientorders_path(id: @clientorder.id, locale: I18n.locale) %>",
data: { payment_method_nonce: payload.nonce }
})
if (err) {
console.log('Error', err);
return;
}
// Add the nonce to the form and submit
document.querySelector('#nonce').value = payload.nonce;
form.submit();
});
});
});
</script>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다