Skip to content

Instantly share code, notes, and snippets.

module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class PaypalGateway < Gateway
RECURRING_ACTIONS = Set.new([:add, :cancel, :inquiry, :suspend])
@@API_VERSION = '50.0'
def recurring(money, credit_card, options = {})
options[:name] = credit_card.name if options[:name].blank? && credit_card
# This is a ruby array of other state/province codes and corresponding abbreviations
# that are recognized by PayPal's API as of July 23, 2010
@other_codes = [
['American Samoa', 'AS'],
['Armed Forces', 'AE'],
['Armed Forces Americas', 'AA'],
['Armed Forces Pacific', 'AP'],
['Federated States of Micronesia', 'FM'],
['Guam', 'GU'],
# This is a ruby array of all 2-character IS0-3166-1 country/region codes used
# by PayPal's API as of July 23, 2010
@country_codes = [
['Afghanistan', 'AF'],
['Aland Islands', 'AX'],
['Albania', 'AL'],
['Algeria', 'DZ'],
['American Samoa', 'AS'],
['Andorra', 'AD'],
# This is a ruby array of all U.S. states and corresponding abbreviations that are
# recognized by PayPal's API as of July 23, 2010
@us_state_codes = [
['Alabama', 'AL'],
['Alaska', 'AK'],
['Arizona', 'AZ'],
['Arkansas', 'AR'],
['California', 'CA'],
['Colorado', 'CO'],
# This is a ruby array of all Canadian provinces and corresponding abbreviations
# that are recognized by PayPal's API as of July 23, 2010
@canada_province_codes = [
['Alberta', 'AB'],
['British Columbia', 'BC'],
['Manitoba', 'MB'],
['New Brunswick', 'NB'],
['Newfoundland and Labrador', 'NL'],
['Northwest Territories', 'NT'],
# Setup ActiveMerchant for development mode with Paypal Sandbox
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
::GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(
:login => '[Add PayPal API login here]',
:password => '[Add PayPal API password here]',
:signature => '[Add PayPal API signature here]'
)
end
# Setup ActiveMerchant for production mode with Paypal Website Payments Pro
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :production
::GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(
:login => '[Add PayPal API login here]',
:password => '[Add PayPal API password here]',
:signature => '[Add PayPal API signature here]'
)
end
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class PaypalGateway < Gateway
RECURRING_ACTIONS = Set.new([:add, :modify, :inquiry, :suspend, :reactivate, :cancel])
# Creates a recurring profile
def create_recurring_profile(*args) #:nodoc:
request = build_recurring_request(:add, *args)
commit('CreateRecurringPaymentsProfile', request)
require File.dirname(__FILE__) + '/paypal/paypal_common_api'
require File.dirname(__FILE__) + '/paypal_express'
require File.dirname(__FILE__) + '/paypal/paypal_recurring_payments' # Add this line
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class PaypalGateway < Gateway
include PaypalCommonAPI
...
credit_card = {
:type => '[cc type, e.g. 'visa']',
:number => '[cc number, from test account]',
:verification_value => '123',
:month => '[expiration month, from test account]',
:year => '[expiration year, from test account]',
:first_name => '[first name, can be anything]',
:last_name => '[last name, can be anything]',
:street_1 => '[street address, can be anything]',
:city => '[city, can be anything]',