簡體   English   中英

Rails Stripe Js可變金額結帳

[英]Rails Stripe Js variable amount checkout

據我所知,最好的問題是,沒有調用條紋簽出模式,因此請求在沒有設置stripeToken的情況下直接通過了我的收費控制器,因此引發了源為空錯誤。

這是他們的安裝教程的鏈接: https : //stripe.com/docs/recipes/variable-amount-checkout

因此,我在閱讀時實際上已經復制/粘貼了他們的代碼,只是簡單地修改了最小數量。 我的api鍵有錯誤,但是我克服了這個問題。

看一下我的錯誤:您為'source'傳遞了一個空白字符串。 您應從請求中刪除“源”參數,或提供非空白值。

Stripe::Charge.create(
      :amount => @amount,
      :currency => 'usd',
      :source => params[:stripeToken],

參數:

{“ utf8” =>“✓”,“ authenticity_token” =>“長碼...”,“金額” =>“ 6”,“ stripeToken” =>“”}

模態根本不會出現在此錯誤之前。 我懷疑捐贈按鈕事件處理程序根本不會調用檢出模式js。

<script src="https://checkout.stripe.com/checkout.js"></script>

<script>
var handler = StripeCheckout.configure({
  key: '<%= Rails.configuration.stripe[:publishable_key] %>',
  locale: 'auto',
  name: 'Ragnar\'s Redoubt',
  description: 'One-time donation',
  token: function(token) {
    $('input#stripeToken').val(token.id);
    $('form').submit();
  }
});

$('#donateButton').on('click', function(e) {
  e.preventDefault();

  $('#error_explanation').html('');

  var amount = $('input#amount').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>Donation amount must be at least $1.</p>');
  }
  else {
    amount = amount * 100; // Needs to be an integer!
    handler.open({
      amount: Math.round(amount)
    })
  }
});

// Close Checkout on page navigation
$(window).on('popstate', function() {
  handler.close();
});
</script>

我是javascript新手,但看不到handle.open()如何打開上方的簽出腳本。 var handle也沒有調用它,所以我在這里缺少什么?

有回答我自己的菜鳥問題的風險...

我從freenode的#stripe irc頻道獲得了很棒的幫助。

即使我在此處正確鍵入,我仍會以某種方式錯過鍵入?

因此,我是正確的,這是一個模態不顯示的問題,正如#stripe上的樂於助人的人所說,“打開chrome開發人員工具並檢查控制台以查看是否存在任何JavaScript錯誤”。

確實存在,它直接導致我出現拼寫錯誤。 因此,+ 1#stripe,+ 1 chrome工具。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM