【问题标题】:How to display Order id in paypal transaction detail page?如何在贝宝交易详情页面显示订单编号?
【发布时间】:2015-05-27 16:26:52
【问题描述】:

我们正在使用 rails4 ,activemerchant 1.47.0 。

通常情况下,在 paypal 中的订单交易的交易详情页面中不会显示订单 ID。

如何在paypal交易的交易详情页面设置订单id?

这些是用于交易和购买的方法。

 response = ACTIVE_GATEWAY.setup_purchase((payment.amount * 100),
                                           ip: request.remote_ip,
                                           return_url: "url",
                                           cancel_return_url: url,
                                           currency: "USD",
                                           items: [{name: order.number, description: "Order description", quantity: "1", amount: (payment.amount * 100)}]
  )
  redirect_to ACTIVE_GATEWAY.redirect_url_for(response.token)

购买

 purchase_response = ACTIVE_GATEWAY.purchase((payment.amount* 100), {
            :ip => request.remote_ip,
            :token => token,
            :payer_id => payerID
        })

谢谢

【问题讨论】:

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


    【解决方案1】:

    请这样尝试。

    这是用于开发环境的。

    config/development.rb

    config.after_initialize do
        ActiveMerchant::Billing::Base.mode = :test
        paypal_options = {
            :login => "email_id",
            :password => "password",
            :signature => "signature"
        }
        ::EXPRESS_GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
    end
    

    控制器::

    def express_paypal
        order = current_user.orders.find(params[:id])
        amount = order.total_amount
        response = EXPRESS_GATEWAY.setup_purchase(amount,
            :ip                => request.remote_ip,
            :return_url        => url_for(:action => 'complete', :id => order.id),
            :cancel_return_url => url_for(:action => 'show', :controller => "orders",:id => order.id),
            :allow_guest_checkout => true,
            :items =>
                [{ :name => current_user.to_s,
                :quantity => 1,
                :description => "Items",
                :amount => amount
                }]
            )
        if response.present?
            redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token)
        end
    end
    
    
    def complete   
        order = current_user.orders.find(params[:id])
        amount = order.total_amount
        begin
         purchase = EXPRESS_GATEWAY.purchase(amount,
                :ip       => request.remote_ip,
                :payer_id => params[:PayerID],
                :token    => params[:token]
            )
        rescue Exception => e
            logger.error "Paypal error while creating payment: #{e.message}"
            flash[:error] = e.message
        end
        unless purchase.success?
            flash[:error] = "Unfortunately an error occurred:" + purchase.message
        else
            flash[:notice] = "Thank you for your payment"
        end
      redirect_to :action => "show", :id => order.id
    end
    

    【讨论】:

    • 交易详情页没有标注订单id。
    猜你喜欢
    • 1970-01-01
    • 2013-02-03
    • 1970-01-01
    • 2020-09-26
    • 2015-12-21
    • 1970-01-01
    • 2023-03-30
    • 2013-07-11
    • 2020-06-20
    相关资源
    最近更新 更多