【发布时间】: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