2

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 Shopping cart content. 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

express_checkout

however during the transaction, item details appears, Item details 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.

Bibek Sharma
  • 3,210
  • 6
  • 42
  • 64

1 Answers1

1

Are you including the line item details in the DoExpressCheckout call as well? If you are only sending them in the SetExpressCheckout call, they would show in the checkout screen as listed above, but if not included in the DoExpressCheckout call, they would not show in the transaction details.

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

  • great.So what should I do use DoExpressCheckout in stead of SetExpressCheckout method? or I should call one after another.It'll be great If you specify order. – Bibek Sharma Oct 29 '15 at 14:59
  • Express Checkout is done in 3 calls: (1) SetExpressCheckout: Your cart sends details to PayPal. PayPal responds with a token and you redirect customer to PayPal to checkout (2) GetExpressCheckoutDetails: After customer completes checkout and returns to your site, your cart calls this to get the information about the checkout. (3) DoExpressCheckout: Completes the payment. You should pass the line item details in both steps 1 and 3 – PayPal_MSI_Robert Oct 29 '15 at 15:14
  • Great, I'll try this tomorrow in the office. Thank you very much – Bibek Sharma Oct 29 '15 at 15:25
  • Thanks man, I solved my problem. I added Items details in purchase method in activemerchant (equivalent to "DoExpressCheckout" and It get fixed. Please kindly add https://github.com/activemerchant/active_merchant/issues/1912 link In your answer. So that other having the same issue can find the solution. – Bibek Sharma Oct 30 '15 at 06:48
  • I've another issue regarding PayPal.please kindly have a look http://stackoverflow.com/questions/33359960/opensslsslsslerror-ssl-connect-returned-1-errno-0-state-sslv3-read-server-c – Bibek Sharma Oct 30 '15 at 06:53