====== 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 ======
[[http://activemerchant.org/|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 [[http://railscasts.com/episodes/145-integrating-active-merchant|Railscast tutorial]]
[[https://github.com/paypal/adaptiveaccounts-sdk-ruby|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 [[https://developer.paypal.com/docs/classic/adaptive-accounts/ht_ap-basicCreateAccount-curl-etc/| 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 [[https://developer.paypal.com/docs/classic/adaptive-payments/ht_ap-embeddedPayment-curl-etc/|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.
[[https://wiki.exphosted.com/doku.php/payment_integration#implementation/|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