KoducExpressPaypal

KoducExpressPaypal is a simple gem used for fulfilling the requirement of one time Paypal Express Checkout integration using NVP(Name Value Pair). The chief principle of designing this library is the involvement of different internal Express Checkout Paypal APIs.

It is developed for the usage in Ruby on Rails web applications and integrates as a Rails plugin.

It is developed in November 2015 by KSolves team with the help of valuable contributors.

Installation

From Git

Check out the latest source from git using:

git clone https://github.com/kartiksolves/koduc-paypal-express.git

if you're using Bundler, just add the following to your Gemfile:

gem 'koduc_express_paypal'

And then execute:

$ bundle

Or install it yourself as:

$ gem install koduc_express_paypal

Usage

This simple example demonstrates how a purchase can be made using the KoducExpressPaypal gem.

require 'koduc_express_paypal'  

# Declare the following paypal credentials in the same format in the environment files present in the config folder. Use development.rb for sandbox credentials and production.rb for live credentials. Write everything is string.

config.paypal_credentials = {
            :USER => <userid>, 
            :PWD => <password>, 
            :SIGNATURE => <signature>
         }

# Set the environment in the format given below. 
# Default it will be a sandbox mode.

# For Sandbox mode use
KsCheckEnvironment::ks_sandbox(true)

# For Live mode use
KsCheckEnvironment::ks_sandbox(false)

# Form a hash of the required parameters in the format given below.
# All the fields are mandatory
# payment_amount   => payment amount (Integers and float values are allowed else it will throw error message )
# payment_action   => type of transaction (Only alphabets are allowed.)
# payment_currency => payment currency code (Only alphabets are allowed in capital letters.)
# cancel_url       => redirect URL for use if the customer does not authorize payment
# return_url       => redirect URL for use if the customer authorizes payment
# Pass the parameters in string

hash = {:payment_amount =><paymentAmount>,:payment_action=><paymentAction>,:payment_currency=><paymentCurrency>,:cancel_url=><cancelURL>,:return_url=><returnURL>}

# Form an object using the above hash

obj = KsExpressPaypal::KsRequest.new(hash)

# Check if the passed parameters are valid using the object formed above

validity = obj.valid?

# The format of the response obtained is {success: true/false ,response:[Error Array]}
# The value of success is true is the parameters are verified completely else it will be false.
# The value of response will be an Array consisting of the error messages in case the validation of the parameters failed. In case the value of success is true the response will be an empty array.

# If the success is true call the following method with the same object formed above

set_checkout = obj.ks_set_express_checkout

# The format of the response in case of success is {success: true ,response:[Response returned from Paypal]}
# The format of the response in case of failure is {success: false ,response:[Error Message returned from Paypal]} 
# If the above call is successful the response will contain the TOKEN. 
# If the above call is a failure refer the paypal errors.

# In case of success, using the token valued returned from above, redirect the customer to PayPal so they can approve the transaction:

# For sandbox 
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=<tokenValue>

# For LIVE redirect the customer to 
https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=<tokenValue>

# The redirect presents the customer with a PayPal log-in page. After the customer logs in, PayPal displays the transaction details on the Payments Review page. The customer approves the payment on this page by clicking Continue.

# If the customer approves the payment, PayPal directs the customer to the payment confirmation page (the return URL specified above in the parameters described above). If the customer doesn't authorize the payment, PayPal directs the customer to the cancel URL that you also specified in the parameters described above, and you can attempt to re-initiate the checkout.

# If the customer approves the payment, find the checkout details using the following method by passing the TOKEN obtained above with the same object.
# It is advisable to display the details on the payment confirmation page using the below method

checkout_details = KsExpressPaypal::KsRequest.ks_checkout_details(<tokenValue>)

# The format of the response in case of success is {success: true ,response:[Response returned from Paypal]}
# The format of the response in case of failure is {success: false ,response:[Error Message returned from Paypal]} 
# If the above call is successful the response will contain the TOKEN and the various other details with the PAYERID if the customer has verified the payment. Utilise the details obtained above accordingly.
# If the above call is a failure refer the paypal errors.

# In addition to the transaction details, your payment confirmation page should include a Confirm button. When the customer confirms the payment, call the below method to capture (collect) the payment. The following sample shows how to specify the PayerID and token value returned from the previous call. Provide the Payment Action with token and payerId:

do_checkout = KsExpressPaypal::KsRequest.ks_do_checkout(<tokenValue>,<paymentAction>,<payerId>)

# When PayPal processes the above call, it captures the payment by transferring the funds from the customer account to the appropriate merchant account and sends a confirmation e-mail to the customer.

# The format of the response in case of success is {success: true ,response:[Response returned from Paypal]}
# The format of the response in case of failure is {success: false ,response:[Error Message returned from Paypal]} 
# Refer the paypal errors in case of failure.

Queries and Issues

Your valuable queries and suggestions are welcomed. Please report the issues on GitHub at https://github.com/kartiksolves/koduc-paypal-express

Contact

If you have any query, need support or advice just DROP us a line and we’ll be in touch very soon.

Email: [email protected]

You can also contact us at +91-120-4540178

We’d love to hear from you! :) :)