Class: ActiveMerchant::Billing::PayflowNvpUkGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/payflow_nvp_uk.rb

Constant Summary collapse

TEST_URL =
'https://pilot-payflowpro.paypal.com'
LIVE_URL =
'https://payflowpro.paypal.com'
TRANSACTIONS =
{
  :purchase       => "S",
  :authorization  => "A",
  :capture        => "D",
  :void           => "V",
  :credit         => "C",
  :recurring      => "R"
}
PERIODS =
{
  :daily => "EDAY",
  :weekly => "WEEK",
  :biweekly => "BIWK",
  :semimonthly => "SMMO",
  :quadweekly => "FRWK",
  :monthly => "MONT",
  :quarterly => "QTER",
  :semiyearly => "SMYR",
  :yearly => "YEAR"
}
RECURRING_ACTIONS =
{
  :create => "A",
  :modify => "M",
  :deactivate => "C",
  :reactivate => "R",
  :inquiry => "I"
}
AUTO_BILLING =
{
  :no_auto => "NoAutoBill",
  :add_to_next => "AddToNextBilling"
}
INITAMT_ACTIONS =
{
  :cancel => "CancelOnFailure",
  :continue => "ContinueOnFailure"
}

Constants inherited from Gateway

Gateway::DEBIT_CARDS

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, inherited, supports?

Methods included from Utils

generate_unique_id

Methods included from CreditCardFormatting

#format

Methods included from RequiresParameters

#requires!

Methods included from PostsData

included, #ssl_get, #ssl_post

Constructor Details

#initialize(options = {}) ⇒ PayflowNvpUkGateway

Creates a new PayflowNvpUkGateway

The gateway requires that a valid login and password be passed in the options hash.

Parameters

  • options

    • :login - Your Payflow login

    • :password - Your Payflow password

    • :vendor - Your vendor ID. If not present then the login is used



85
86
87
88
89
90
91
# File 'lib/active_merchant/billing/gateways/payflow_nvp_uk.rb', line 85

def initialize(options = {})
  requires!(options, :login, :password)
  @options = options
  @options[:partner] = partner if @options[:partner].blank?
  @options[:vendor] = options[:login] if @options[:vendor].blank?
  super
end

Instance Method Details

#authorize(money, creditcard, options = {}) ⇒ Object

Performs an authorization transaction. This is required due to Visa and Mastercard restrictions, in that a customer’s card cannot be charged until the goods have been dispatched. An authorization allows an amout to be reserved on a customer’s card, bringing down the available balance or credit, but they are not actually charged until a subsequent capture step actually captures the funds.

Parameters

  • money - The amount to be charged as an integer value in cents.

  • creditcard - The CreditCard object to be used as a funding source for the transaction.

  • options - A hash of optional parameters

    • :order_id - A unique reference for this order (maximum of 127 characters).

    • :email - The customer’s email address

    • :customer - A unique reference for the customer (maximum of 12 characters).

    • :ip - The customer’s IP address

    • :currency - The currency of the transaction. If present must be one of { AUD, CAD, EUR, JPY, GBP or USD }. If omitted the default currency is used.

    • :billing_address - The customer’s billing address as a hash of address information.

      • :address1 - The billing address street

      • :city - The billing address city

      • :state - The billing address state

      • :country - The 2 digit ISO billing address country code

      • :zip - The billing address zip code

    • :shipping_address - The customer’s shipping address as a hash of address information.

      • :address1 - The shipping address street

      • :city - The shipping address city

      • :state - The shipping address state code

      • :country - The 2 digit ISO shipping address country code

      • :zip - The shipping address zip code



132
133
134
135
136
137
138
139
140
141
142
# File 'lib/active_merchant/billing/gateways/payflow_nvp_uk.rb', line 132

def authorize(money, creditcard, options = {})
  post = {}
  add_invoice(post, options)
  add_creditcard(post, creditcard)
  add_currency(post, money, options)
  add_address(post, options[:billing_address] || options[:address])
  add_address(post, options[:shipping_address], "shipto")
  add_customer_data(post, options)

  commit(TRANSACTIONS[:authorize], money, post)
end

#cancel_recurring(profile_id) ⇒ Object

Cancel a recurring profile.

Parameters

  • profile_id - the id of the recurring profile to cancel



305
306
307
308
309
310
311
312
# File 'lib/active_merchant/billing/gateways/payflow_nvp_uk.rb', line 305

def cancel_recurring(profile_id)
  post = {}

  post[:action] = RECURRING_ACTIONS[:deactivate]
  post[:origprofileid] = profile_id.to_s

  commit(TRANSACTIONS[:recurring], nil, post)
end

#capture(money, authorization, options = {}) ⇒ Object

Captures authorized funds.

Parameters

  • money - The amount to be authorized as an integer value in cents. Payflow does support changing the captured amount, so whatever is passed here will be captured.

  • authorization - The authorization reference string returned by the original transaction’s Response#authorization.

  • options - not currently used.



188
189
190
191
192
193
# File 'lib/active_merchant/billing/gateways/payflow_nvp_uk.rb', line 188

def capture(money, authorization, options = {})
  post = {}
  post[:origid] = authorization

  commit(TRANSACTIONS[:capture], money, post)
end

#credit(money, authorization_or_card, options = {}) ⇒ Object

Process a refund to a customer.

Parameters

  • money - The amount to be credited as an integer value in cents.

  • authorization_or_card - The CreditCard you want to refund to OR the PayPal PNRef of a previous transaction. It depends on the settings in your PayPal account as to whether non referenced credits are permitted. The default is that they are not.

  • options - not currently used



214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/active_merchant/billing/gateways/payflow_nvp_uk.rb', line 214

def credit(money, authorization_or_card, options = {})
  post = {}

  if authorization_or_card.is_a?(String)
    # perform a referenced credit
    post[:origid] = authorization
  else
    # perform an unreferenced credit
    add_creditcard(post, creditcard)
  end

  commit(TRANSACTIONS[:credit], money, post)
end

#gateway_urlObject

Return the url of the gateway



94
95
96
# File 'lib/active_merchant/billing/gateways/payflow_nvp_uk.rb', line 94

def gateway_url
  return test? ? TEST_URL : LIVE_URL
end

#modify_recurring(profile_id, money, creditcard, options = {}) ⇒ Object

Modify a recurring payments profile

Parameters

  • :profile_id - The profile_id of the profile we want to amend.

  • money - The amount that the recurring profile is to be set up for as an integer value in cents.

  • creditcard - The CreditCard object to be used as a funding source for the recurring profile.

  • options - A hash of parameters (some optional).

    • :name - The name of the customer to be billed. If omitted the name from the creditcard is used.

    • :billing_address - The billing address of the customer. Either :billing_address or :address must be present

    • :address - The address of the customer. Not required if :billing_address is present.

    • :shipping_address - Optional shipping address for the customer.

    • :periodicity - The frequency that the recurring payments will occur at. Can be one of: [:daily, :weekly, :biweekly (every 2 weeks), :semimonthly (twice every month), :quadweekly (once every 4 weeks), :monthly (every month on the same date as the first payment), :quarterly (every 3 months on the same date as the first payment), :semiyearly (every 6 months on the same date as the first payment), :yearly.

    • :payments - Integer value describing the number of payments to be made. If set to 0 then profile will continue until terminated

    • <tt>:comment<tt> - Optional description of the goods or service being purchased

    • :max_failed_payments - The number of payments that are allowed to fail before PayPal suspends the profile. Defaults to 0 which means PayPal will never suspend the profile until the term is completed. PayPal will keep attempting to process failed payments.

    • :currency - The currency of the transaction. If present must be one of { AUD, CAD, EUR, JPY, GBP or USD }. If omitted the default currency is used.

    • :description - The description of the profile. Required for the profile to be created successfully.

    • :autobilloutstanding - Controls whether to automatically bill the outstanding balance amount in the next payment. Can be either :no_auto or :add_to_next. Defaults to :no_auto



281
282
283
# File 'lib/active_merchant/billing/gateways/payflow_nvp_uk.rb', line 281

def modify_recurring(profile_id, money, creditcard, options = {})
  recurring(money, creditcard, options.merge(:profile_id => profile_id))
end

#purchase(money, creditcard, options = {}) ⇒ Object

A purchase transaction authorizes and captures in a single hit. We can only do this for transactions where you provide immediate fulfillment of products or services.

Parameters

  • money - The amount to be charged as an integer value in cents.

  • creditcard - The CreditCard object to be used as a funding source for the transaction.

  • options - A hash of optional parameters

    • :order_id - A unique reference for this order (maximum of 127 characters).

    • :email - The customer’s email address

    • :customer - A unique reference for the customer (maximum of 12 characters).

    • :ip - The customer’s IP address

    • :currency - The currency of the transaction. If present must be one of { AUD, CAD, EUR, JPY, GBP or USD }. If ommitted the default currency is used.

    • :billing_address - The customer’s billing address as a hash of address information.

      • :address1 - The billing address street

      • :city - The billing address city

      • :state - The billing address state

      • :country - The 2 digit ISO billing address country code

      • :zip - The billing address zip code

    • :shipping_address - The customer’s shipping address as a hash of address information.

      • :address1 - The shipping address street

      • :city - The shipping address city

      • :state - The shipping address state code

      • :country - The 2 digit ISO shipping address country code

      • :zip - The shipping address zip code



169
170
171
172
173
174
175
176
177
178
179
# File 'lib/active_merchant/billing/gateways/payflow_nvp_uk.rb', line 169

def purchase(money, creditcard, options = {})
  post = {}
  add_invoice(post, options)
  add_creditcard(post, creditcard)
  add_currency(post, money, options)
  add_address(post, options[:billing_address] || options[:address])
  add_address(post, options[:shipping_address], "shipto")
  add_customer_data(post, options)

  commit(TRANSACTIONS[:purchase], money, post)
end

#recurring(money, creditcard, options = {}) ⇒ Object

Create or modify a recurring profile.

Parameters

  • money - The amount that the recurring profile is to be set up for as an integer value in cents.

  • creditcard - The CreditCard object to be used as a funding source for the recurring profile.

  • options - A hash of parameters (some optional).

    • :profile_id - If present then we are modifying an existing profile, and this :profile_id identifies the profile we want to amend. If not present then we are creating a new recurring payments profile.

    • :starting_at - Takes a Date, Time or string in MMDDYYYY format. The date must be in the future.

    • :name - The name of the customer to be billed. If omitted the name from the creditcard is used.

    • :billing_address - The billing address of the customer. Either :billing_address or :address must be present

    • :address - The address of the customer. Not required if :billing_address is present.

    • :shipping_address - Optional shipping address for the customer.

    • :periodicity - The frequency that the recurring payments will occur at. Can be one of: [:daily, :weekly, :biweekly (every 2 weeks), :semimonthly (twice every month), :quadweekly (once every 4 weeks), :monthly (every month on the same date as the first payment), :quarterly (every 3 months on the same date as the first payment), :semiyearly (every 6 months on the same date as the first payment), :yearly.

    • :payments - Integer value describing the number of payments to be made. If set to 0 then profile will continue until terminated

    • <tt>:comment<tt> - Optional description of the goods or service being purchased

    • :max_failed_payments - The number of payments that are allowed to fail before PayPal suspends the profile. Defaults to 0 which means PayPal will never suspend the profile until the term is completed. PayPal will keep attempting to process failed payments.

    • :currency - The currency of the transaction. If present must be one of { AUD, CAD, EUR, JPY, GBP or USD }. If omitted the default currency is used.

    • :description - The description of the profile. Required for the profile to be created successfully.

    • :optionaltrxamt - Optional initial transaction amount in cents.

    • :failedinitamtaction - What to action to perform if the initial transaction fails. Can be either :continue or :cancel. Defaults to :cancel.

    • :autobilloutstanding - Controls whether to automatically bill the outstanding balance amount in the next payment. Can be either :no_auto or :add_to_next. Defaults to :no_auto



250
251
252
253
254
255
256
257
258
259
260
# File 'lib/active_merchant/billing/gateways/payflow_nvp_uk.rb', line 250

def recurring(money, creditcard, options = {})
  post = {}
  add_creditcard(post, creditcard)
  add_currency(post, money, options)
  add_address(post, options[:billing_address] || options[:address])
  add_address(post, options[:shipping_address], "shipto")
  add_customer_data(post, options)
  add_recurring_info(post, creditcard, options)

  commit(TRANSACTIONS[:recurring], money, post)
end

#recurring_inquiry(profile_id, options = {}) ⇒ Object

Inquire about the status of a previously created recurring profile.

Parameters

  • profile_id - the id of the recurring profile we want to get the details of.

  • options - not currently used



291
292
293
294
295
296
297
298
# File 'lib/active_merchant/billing/gateways/payflow_nvp_uk.rb', line 291

def recurring_inquiry(profile_id, options = {})
  post = {}

  post[:action] = RECURRING_ACTIONS[:inquiry]
  post[:origprofileid] = profile_id.to_s

  commit(TRANSACTIONS[:recurring], nil, post)
end

#test?Boolean

Is the gateway in test mode?

Returns:

  • (Boolean)


99
100
101
# File 'lib/active_merchant/billing/gateways/payflow_nvp_uk.rb', line 99

def test?
  @options[:test] || super
end

#void(authorization, options = {}) ⇒ Object

Voids an authorization or delayed capture

Parameters

  • authorization - The authorization reference string returned by the original transaction’s Response#authorization.

  • options - Not currently used.



201
202
203
204
205
206
# File 'lib/active_merchant/billing/gateways/payflow_nvp_uk.rb', line 201

def void(authorization, options = {})
  post = {}
  post[:origid] = authorization

  commit(TRANSACTIONS[:void], nil, post)
end