【问题标题】:Shopping Cart Contents missing Transaction details not shown on Paypal Express Checkout购物车内容缺失 Paypal Express Checkout 上未显示交易详情
【发布时间】:2016-01-29 07:29:27
【问题描述】:

我正在使用ActiveMerchant我正在尝试使用快速结帐和自适应付款来集成 PayPal。在自适应支付中,我能够查看 购物车内容 如下。我的代码就是这样,按预期工作。

 def adaptive_checkout

    listing = Listing.find(session[:listing_id].to_f)


    total_amount_in_cents = listing.price_cents

    service_charge_rate = 5 #in percentage 5%

    service_charge_in_cents = total_amount_in_cents * service_charge_rate / 100

    service_charge_in_dollor = service_charge_in_cents / 100.00 # this will be for secondary user (Admin of the system)

    total_amount_in_dollar = total_amount_in_cents / 100.00 # this will be for primary receiver

    seller_email = PaypalAccount.where(person_id: listing.author_id).last.email # This is the Primary receiver

    system_admin_email = PaypalAccount.where(active: true)
                             .where("paypal_accounts.community_id IS NOT NULL && paypal_accounts.person_id IS NULL")
                             .first.email # This is the Secondary receiver


    recipients = [
        {
            email: seller_email,
            amount: total_amount_in_dollar ,
            primary: true
        },

        {
            email: system_admin_email,
            amount: service_charge_in_dollor,
            primary: false
        }
    ]

    response = ADAPTIVE_GATEWAY.setup_purchase(
        action_type: "CREATE",
        return_url: "http://esignature.lvh.me:3000/en/transactions/status",
        cancel_url: "http://esignature.lvh.me:3000/",
        ipn_notification_url: "http://0dbf7871.ngrok.io/en/transactions/notification",
        receiver_list: recipients
    )


    ADAPTIVE_GATEWAY.set_payment_options(

        pay_key: response["payKey"],
        receiver_options: [
            {
                description: "Your purchase of #{listing.title}",
                invoice_data: {
                    item: [
                        {
                            name: listing.title,
                            item_count: 1,
                            item_price: total_amount_in_dollar,
                            price: total_amount_in_dollar
                        }
                    ]
                },
                receiver: {email: seller_email}
            },
            {
                description: "Service charge for purchase of #{listing.title} ",
                invoice_data: {
                    item: [
                        {
                            name: "Service charge for purchase of #{listing.title}",
                            item_count: 1,
                            item_price: service_charge_in_dollor,
                            price: service_charge_in_dollor
                        }
                    ]
                },
                receiver: {email: system_admin_email}
            }
        ]
    )



    # For redirecting the customer to the actual paypal site to finish the payment.
    redirect_to (ADAPTIVE_GATEWAY.redirect_url_for(response["payKey"]))
  end

但是使用express_checkout,我在交易详情中看不到我的购物车内容

但是在交易过程中,会出现项目详细信息, 对于快速结帐,我的代码是这样的

def express_checkout

    listing = Listing.find(session[:listing_id].to_f)

    response = EXPRESS_GATEWAY.setup_purchase(session[:amount].to_f,
                                              ip: request.remote_ip,
                                              return_url: "http://esignature.lvh.me:3000/en/transactions/status",
                                              cancel_return_url: "http://esignature.lvh.me:3000/",
                                              currency: "USD",
                                              allow_guest_checkout: true,
                                              items: [{name: listing.title, description: listing.description, quantity: session[:number_of_days], amount: listing.price_cents},
                                                      {name: "Service Charge", amount: session[:service_charge]}
                                              ]
    )

    redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token)

  end

  def status
    if (params[:token].present? && params[:PayerID].present?)
      token = params[:token]
      @response = EXPRESS_GATEWAY.details_for(token).params
      express_purchase_options = {
          :ip => request.remote_ip,
          :token => params[:token],
          :payer_id => params[:PayerID]
      }

      response = EXPRESS_GATEWAY.purchase(session[:amount].to_f, express_purchase_options)


      if response.message == "Success"
        listing = Listing.find(session[:listing_id].to_f)
        BookingInfo.create!(listing_id: listing.id, start_on: session[:start_date].to_date, end_on: session[:end_date].to_date)
        render 'status'
      else
        render 'status_error'
      end
      reset_session_params
    else
      reset_session_params
      redirect_to homepage_without_locale_path
    end

  end

我尝试使用set_payment_options 方法但引发方法丢失错误。有没有其他方法可以在快速结帐时附加商品详细信息。

【问题讨论】:

    标签: ruby-on-rails paypal express-checkout activemerchant


    【解决方案1】:

    您是否也在 DoExpressCheckout 调用中包含行项目详细信息?如果您仅在 SetExpressCheckout 调用中发送它们,它们将显示在上面列出的结帐屏幕中,但如果未包含在 DoExpressCheckout 调用中,它们将不会显示在交易详细信息中。

    https://github.com/activemerchant/active_merchant/issues/1912

    【讨论】:

    • 太棒了。那么我应该如何使用 DoExpressCheckout 而不是 SetExpressCheckout 方法呢?或者我应该一个接一个地打电话。如果你指定顺序就很好了。
    • 快速结帐通过 3 次调用完成: (1) SetExpressCheckout:您的购物车将详细信息发送到 PayPal。 PayPal 以令牌响应,您将客户重定向到 PayPal 以结帐 (2) GetExpressCheckoutDetails:客户完成结帐并返回您的站点后,您的购物车调用它以获取有关结帐的信息。 (3) DoExpressCheckout:完成支付。您应该在第 1 步和第 3 步中传递订单项详细信息
    • 太好了,我明天在办公室试试这个。非常感谢
    • 谢谢,我解决了我的问题。我在activemerchant的购买方法中添加了项目详细信息(相当于“DoExpressCheckout”并且它得到了修复。请在您的答案中添加github.com/activemerchant/active_merchant/issues/1912链接。以便其他有相同问题的人可以找到解决方案。
    • 我有另一个关于 PayPal 的问题。请查看stackoverflow.com/questions/33359960/…
    猜你喜欢
    • 2015-04-04
    • 2015-04-22
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 2018-08-07
    • 2020-08-06
    • 2021-06-06
    • 2015-11-13
    相关资源
    最近更新 更多