Class Paypal
In: lib/ruby-paypal/paypal.rb
Parent: Object
Author:Chang Sau Sheong (sausheong.chang@gmail.com)
Copyright:Copyright (c) 2007 Chang Sau Sheong
License:Distributes under the same terms as Ruby
Version:0.0.2

Installing Ruby-PayPal

A lightweight ruby wrapper for PayPal NVP APIs. To install type the following at the command line:

  $ gem install ruby-paypal

Using Ruby-PayPal

It‘s critical that you understand how PayPal works and how the PayPal NVP API works. You should be relatively well-versed in the NVP API Developer Guide and Reference (www.paypal.com/en_US/ebook/PP_NVPAPI_DeveloperGuide/index.html). You should also visit and register yourself with the PayPal Developer Network and get a Sandbox account with in the PayPal Development Central (developer.paypal.com/).

Note that this library only supports the API signature method of securing the API credentials.

Direct Payment

To use credit card payment through PayPal, you need to use the DoDirectPayment APIs:

        username = <PayPal API username>
        password = <PayPal API password>
        signature = <PayPal API signature>

        ipaddress = '192.168.1.1' # can be any IP address
        amount = '100.00' # amount paid
        card_type = 'VISA' # can be Visa, Mastercard, Amex etc
        card_no = '4512345678901234' # credit card number
        exp_date = '022010' # expiry date of the credit card
        first_name = 'Sau Sheong'
        last_name = 'Chang'

    paypal = Paypal.new(username, password, signature) # uses the PayPal sandbox
    response = paypal.do_direct_payment_sale(ipaddress, amount, card_type,
                           card_no, exp_date, first_name, last_name)
        if response.ack == 'Success' then
          # do your thing
        end

The above code is for a final sale only.

Note that the credit card number is checked against a modulo-10 algorithm (Luhn check) as well as a simple credit card type check. For more information please refer to en.wikipedia.org/wiki/Luhn_algorithm and en.wikipedia.org/wiki/Credit_card_number

Express Checkout

To use the customer‘s PayPal account for payment, you will need to use the ExpressCheckout APIs:

<to be documented>

More information

I will be continually providing updates in my blog at blog.saush.com

Methods

Included Modules

CreditCardChecks

Public Class methods

Create a new object with the given user name, password and signature. To enable production access to PayPal change the url to the live PayPal server. Set url to :production to change access to PayPal production servers.

Public Instance methods

Checks and returns information on the card based on the given BIN (Bank Identification Number). Currently inactive since bindatabase.com is down.

Does authorization of a request.

Equivalent of DoAuthorization.

Performs credit card payment with PayPal.

Equivalent of DoDirectPayment.

Performs Luhn check and a simple credit card type check based on the card number.

Performs credit card payment with PayPal, but only requesting for authorization. You need to capture the funds later. Calls do_direct_payment.

Equivalent of DoDirectPayment with the PAYMENTACTION of ‘authorization‘

Performs credit card payment with PayPal, finalizing the sale. Funds are captured immediately. Calls do_direct_payment.

Equivalent of DoDirectPayment with the PAYMENTACTION of ‘sale‘

Gets payment through PayPal for Express Checkout.

Equivalent of DoExpressCheckoutPayment

Re-authorizes an authorized transaction.

Equivalent of DoReauthorization.

Gets the details of the request started through set_express_checkout.

Equivalent of GetExpressCheckoutDetails.

Makes the call to the PayPal NVP API. This is the workhorse method for the other method calls.

Performs payment through PayPal.

Equivalent of SetExpressCheckout.

[Validate]