Rails:paypal-表达没有价值传递给付款

时间:2019-04-09 04:25:59

标签: javascript ruby-on-rails paypal paypal-sandbox

我已经设置了paypal-express按钮,但是当按钮被触发并且控制台提示错误说:ppxo_no_token_passed_to_payment时,似乎出现了问题, 未捕获的错误:错误:付款没有值

$.fn.displayPaypalButton = function() {
  var el = this

  if (el.size() > 0) {
    var product = el.next('.product-meta-info')

    if (product.data('purchasable') == true) {
      var lang = Cookies.get('lang')
      var loc = lang === 'en' ? '_US' : (Cookies.get('lang') + '_' + Cookies.get('lang').toUpperCase())

      paypal.Button.render({
        env: "<%= Rails.env.production? ? 'production' : 'sandbox' %>",
        locale: loc,

        style: {
          size: 'responsive',
          shape: 'rect',
          color: 'gold',
          label: 'checkout',
          tagline: false
        },

        payment: function(data, actions) {
          var productDetail = {
            product_id: product.data('id'),
            qty: $('.quantity-input').val(),
            material_id: $('#material-id-' + product.data('id')).val(),
            transfer_material_id: $('#transfer-material-id-' + product.data('id')).val(),
            bonus_material_id: $('#bonus-material-id-' + product.data('id')).val(),
          }

          return actions.request({
            method: 'post',
            url: '/' + Cookies.get('lang') + '/paypal_express/add_to_cart',
            headers: {
              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            data: productDetail
          }).then(function(res) {
            return res.id
          })
        },

        onAuthorize: function(data, actions) {
          window.location.href = data.returnUrl
        }
      }, ('#' + el.attr('id')))
    }
  }
}

$('#paypal-button').displayPaypalButton()
$('.checkout-button').displayPaypalButton()

here is the error information

0 个答案:

没有答案