Site Tools


Hotfix release available: 2025-05-14b "Librarian". upgrade now! [56.2] (what's this?)
Hotfix release available: 2025-05-14a "Librarian". upgrade now! [56.1] (what's this?)
New release available: 2025-05-14 "Librarian". upgrade now! [56] (what's this?)
Hotfix release available: 2024-02-06b "Kaos". upgrade now! [55.2] (what's this?)
Hotfix release available: 2024-02-06a "Kaos". upgrade now! [55.1] (what's this?)
New release available: 2024-02-06 "Kaos". upgrade now! [55] (what's this?)
Hotfix release available: 2023-04-04b "Jack Jackrum". upgrade now! [54.2] (what's this?)
Hotfix release available: 2023-04-04a "Jack Jackrum". upgrade now! [54.1] (what's this?)
New release available: 2023-04-04 "Jack Jackrum". upgrade now! [54] (what's this?)
Hotfix release available: 2022-07-31b "Igor". upgrade now! [53.1] (what's this?)
Hotfix release available: 2022-07-31a "Igor". upgrade now! [53] (what's this?)
New release available: 2022-07-31 "Igor". upgrade now! [52.2] (what's this?)
New release candidate 2 available: rc2022-06-26 "Igor". upgrade now! [52.1] (what's this?)
New release candidate available: 2022-06-26 "Igor". upgrade now! [52] (what's this?)
Hotfix release available: 2020-07-29a "Hogfather". upgrade now! [51.4] (what's this?)
New release available: 2020-07-29 "Hogfather". upgrade now! [51.3] (what's this?)
New release candidate 3 available: 2020-06-09 "Hogfather". upgrade now! [51.2] (what's this?)
New release candidate 2 available: 2020-06-01 "Hogfather". upgrade now! [51.1] (what's this?)
New release candidate available: 2020-06-01 "Hogfather". upgrade now! [51] (what's this?)
Hotfix release available: 2018-04-22c "Greebo". upgrade now! [50.3] (what's this?)
Hotfix release available: 2018-04-22b "Greebo". upgrade now! [50.2] (what's this?)
paypal_integration

Requirements

Replace WePay with PayPal by keeping the functionalities unaltered.

The following are the key features we support using WePay which are to be replaced using PayPal

1. Create Merchant account.

2. Embedded payment UI.

3. Payment using credit cards.

4. One time payment.

5. Preapprove payments.

Library to access PayPal gateway

ActiveMerchant library can be used to communicate with the payment gateways.

On more detailed explanation on integrating PayPal using active merchant gem take a look at Railscast tutorial

Adaptive Accounts sdk library can be used to create Merchant accounts.

PayPal Adaptive accounts API

Merchant account creation can be implemented by following the steps in Create a PayPal Account Using Adaptive Accounts

Steps: 1. Install Adaptive accounts sdk for ruby

gem "paypal-sdk-adaptiveaccounts"

2. Create a yml config file which contains the API credentials

3. Load the configurations

PayPal::SDK::Core::Config.load('config/paypal.yml',  ENV['RACK_ENV'] || 'development')

4. Eg to create an account:

@api = PayPal::SDK::AdaptiveAccounts::API.new(
  :mode      => "sandbox",  # Set "live" for production
  :app_id    => "APP-80W284485P519543T",
  :username  => "jb-us-seller_api1.paypal.com",
  :password  => "WX4WTU3S8MY44S7F",
  :signature => "AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-RWy",
  :device_ipaddress => "127.0.0.1",
  :sandbox_email_address => "platform.sdk.seller@gmail.com" )

# Build request object
@create_account = @api.build_create_account({
  :accountType => "Personal",
  :name => {
    :salutation => "Mr.",
    :firstName => "Bonzop",
    :middleName => "Simore",
    :lastName => "Zaius" },
  :dateOfBirth => "1968-01-01",
  :address => {
    :line1 => "1968 Ape Way",
    :city => "Austin",
    :state => "TX",
    :postalCode => "78750",
    :countryCode => "US" },
  :contactPhoneNumber => "5126914160",
  :homePhoneNumber => "5126914160",
  :mobilePhoneNumber => "5126914160",
  :currencyCode => "USD",
  :citizenshipCountryCode => "US",
  :preferredLanguageCode => "en_US",
  :notificationURL => "http://localhost:3000/samples/adaptive_accounts/ipn_notify",
  :emailAddress => "newEmailAddress@paypal.com",
  :registrationType => "Web",
  :createAccountWebOptions => {
    :returnUrl => "http://localhost:3000/samples/adaptive_accounts/create_account",
    :showAddCreditCard => true } })

# Make API call & get response
@create_account_response = @api.create_account(@create_account)

PayPal Adaptive payment API

Preapproval and embedded checkout comes under the Adaptive Payments API of PayPal.

Payment Steps:

1. Install Active merchant gem

gem 'activemerchant'

2. Configure values in your respective config environment file.

config.after_initialize do
  ActiveMerchant::Billing::Base.mode = :test
end

3. Create a Object for PayPal adaptive gateway

gateway = ActiveMerchant::Billing::PaypalAdaptivePaymentGateway.new(:login =>"xxx.xxx.com",:password => "XXXXXXXX", :signature => "XXXXXXXXXXXXXXXXXXXX",:appl_id => "APP-80W284485P519543T" )

4. Send request to 'pay' API call

response= gateway.pay(params[:amount].to_i , 'xxxx@xxxx.com', :ip => request.remote_ip,   
     :sender_email => "xxxx@xxxx.com",
     :tracking_id => tracking_id,
     :pay_key => '24',
     :return_url =>"http://test.com,
     :cancel_url=>"http://test.com,
     :ipn_notification_url => "http://test.com/paypal_ipn")

5. It returns paykey, using this paykey redirect to the urls based on requiremnet

redirect_to "https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=#{ response.params['pay_key']}" 
redirect_to "https://www.paypal.com/webscr?cmd=_ap-payment&paykey=#{ response.params['pay_key']}"  

6. For embedded checkouts follow the steps mentioned in PayPal developers documentation: Adaptive payments - Embedded flow

7. Complete transaction with email or visa card and return.

8. Receive “PayPal IPN” to complete your transaction.

Wiki - Payment integration has more details on the implementation of PayPay adaptive payment API for payment and preapprove functionality.

Doubts to be clarrified

Following are some links stating that PayPal's adaptive payments supports preapproval for only PayPal type payments and restricted to credit card type payments, though some other references says preapprovals are supported even for credit card type of payments.

http://stackoverflow.com/questions/16016664/guest-payment-support-in-embedded-payment-flow-for-preapprovals

http://stackoverflow.com/questions/22158521/preapproved-payments-adaptive-payments-nonaccounts

paypal_integration.txt · Last modified: 2018/08/31 16:16 (external edit)