I'm using ActiveMerchantI'm trying to Integrate PayPal using express checkout and Adaptive Payment. In the Adaptive Payment I was able to view Shopping Cart Contents as below . My code was like this which works as expected.
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
But using express_checkout
, I can't see my shopping cart Contents in transaction details
however during the transaction, item details appears,
For the express checkout my code is like this
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
I tried to use set_payment_options
method but raise method missing error. Is there any way other way to attach Item details on express checkout.