我们使用的是rails4,activemerchant 1.47.0。
通常情况下,订单ID不会显示在PayPal订单交易的交易明细页面中。
如何在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
})
由于
答案 0 :(得分:0)
请尝试这样。
这是针对开发环境的。
配置/ 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