mcmire-activemerchant 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +508 -0
- data/CONTRIBUTORS +134 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +136 -0
- data/gem-public_cert.pem +20 -0
- data/lib/active_merchant.rb +46 -0
- data/lib/active_merchant/billing.rb +9 -0
- data/lib/active_merchant/billing/avs_result.rb +98 -0
- data/lib/active_merchant/billing/base.rb +57 -0
- data/lib/active_merchant/billing/check.rb +68 -0
- data/lib/active_merchant/billing/credit_card.rb +159 -0
- data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
- data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
- data/lib/active_merchant/billing/cvv_result.rb +38 -0
- data/lib/active_merchant/billing/expiry_date.rb +34 -0
- data/lib/active_merchant/billing/gateway.rb +163 -0
- data/lib/active_merchant/billing/gateways.rb +18 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +654 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +885 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +244 -0
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +98 -0
- data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +406 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +593 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +229 -0
- data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
- data/lib/active_merchant/billing/gateways/eway.rb +277 -0
- data/lib/active_merchant/billing/gateways/exact.rb +222 -0
- data/lib/active_merchant/billing/gateways/first_pay.rb +172 -0
- data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +270 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +154 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +283 -0
- data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
- data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
- data/lib/active_merchant/billing/gateways/moneris.rb +205 -0
- data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
- data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +279 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
- data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +236 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
- data/lib/active_merchant/billing/gateways/payflow_express.rb +138 -0
- data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
- data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
- data/lib/active_merchant/billing/gateways/payment_express.rb +230 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +326 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
- data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +130 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
- data/lib/active_merchant/billing/gateways/plugnpay.rb +292 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +214 -0
- data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +213 -0
- data/lib/active_merchant/billing/gateways/realex.rb +200 -0
- data/lib/active_merchant/billing/gateways/sage.rb +146 -0
- data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
- data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
- data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
- data/lib/active_merchant/billing/gateways/sage_pay.rb +309 -0
- data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
- data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
- data/lib/active_merchant/billing/gateways/secure_pay_au.rb +157 -0
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
- data/lib/active_merchant/billing/gateways/smart_ps.rb +265 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
- data/lib/active_merchant/billing/gateways/transax.rb +25 -0
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +418 -0
- data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +228 -0
- data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
- data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
- data/lib/active_merchant/billing/integrations.rb +29 -0
- data/lib/active_merchant/billing/integrations/action_view_helper.rb +79 -0
- data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
- data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
- data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
- data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
- data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
- data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
- data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
- data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
- data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
- data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
- data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/helper.rb +93 -0
- data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
- data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
- data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
- data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
- data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
- data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
- data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
- data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/notification.rb +62 -0
- data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
- data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
- data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
- data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/quickpay.rb +17 -0
- data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
- data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
- data/lib/active_merchant/billing/integrations/return.rb +35 -0
- data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
- data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
- data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
- data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
- data/lib/active_merchant/billing/response.rb +32 -0
- data/lib/active_merchant/lib/connection.rb +170 -0
- data/lib/active_merchant/lib/country.rb +319 -0
- data/lib/active_merchant/lib/error.rb +4 -0
- data/lib/active_merchant/lib/post_data.rb +22 -0
- data/lib/active_merchant/lib/posts_data.rb +47 -0
- data/lib/active_merchant/lib/requires_parameters.rb +16 -0
- data/lib/active_merchant/lib/utils.rb +18 -0
- data/lib/active_merchant/lib/validateable.rb +76 -0
- data/lib/certs/cacert.pem +7815 -0
- data/lib/support/gateway_support.rb +58 -0
- metadata +218 -0
@@ -0,0 +1,120 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class PaySecureGateway < Gateway
|
4
|
+
URL = 'https://clearance.commsecure.com.au/cgi-bin/PSDirect'
|
5
|
+
|
6
|
+
self.money_format = :cents
|
7
|
+
|
8
|
+
# Currently Authorization and Capture is not implemented because
|
9
|
+
# capturing requires the original credit card information
|
10
|
+
TRANSACTIONS = {
|
11
|
+
:purchase => 'PURCHASE',
|
12
|
+
:authorization => 'AUTHORISE',
|
13
|
+
:capture => 'ADVICE',
|
14
|
+
:credit => 'REFUND'
|
15
|
+
}
|
16
|
+
|
17
|
+
SUCCESS = 'Accepted'
|
18
|
+
SUCCESS_MESSAGE = 'The transaction was approved'
|
19
|
+
|
20
|
+
self.supported_countries = ['AU']
|
21
|
+
self.homepage_url = 'http://www.commsecure.com.au/paysecure.shtml'
|
22
|
+
self.display_name = 'PaySecure'
|
23
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :diners_club]
|
24
|
+
|
25
|
+
def initialize(options = {})
|
26
|
+
requires!(options, :login, :password)
|
27
|
+
@options = options
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
def purchase(money, credit_card, options = {})
|
32
|
+
requires!(options, :order_id)
|
33
|
+
|
34
|
+
post = {}
|
35
|
+
add_amount(post, money)
|
36
|
+
add_invoice(post, options)
|
37
|
+
add_credit_card(post, credit_card)
|
38
|
+
|
39
|
+
commit(:purchase, money, post)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
# Used for capturing, which is currently not supported.
|
44
|
+
def add_reference(post, identification)
|
45
|
+
auth, trans_id = identification.split(";")
|
46
|
+
post[:authnum] = auth
|
47
|
+
post[:transid] = trans_id
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_amount(post, money)
|
51
|
+
post[:amount] = amount(money)
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_invoice(post, options)
|
55
|
+
post[:merchant_transid] = options[:order_id].to_s.slice(0,21)
|
56
|
+
post[:memnum] = options[:invoice]
|
57
|
+
post[:custnum] = options[:customer]
|
58
|
+
post[:clientdata] = options[:description]
|
59
|
+
end
|
60
|
+
|
61
|
+
def add_credit_card(post, credit_card)
|
62
|
+
post[:cardnum] = credit_card.number
|
63
|
+
post[:cardname] = credit_card.name
|
64
|
+
post[:expiry] = expdate(credit_card)
|
65
|
+
post[:cvv2] = credit_card.verification_value
|
66
|
+
end
|
67
|
+
|
68
|
+
def expdate(credit_card)
|
69
|
+
year = sprintf("%.4i", credit_card.year)
|
70
|
+
month = sprintf("%.2i", credit_card.month)
|
71
|
+
|
72
|
+
"#{month}#{year[-2..-1]}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def commit(action, money, parameters)
|
76
|
+
response = parse( ssl_post(URL, post_data(action, parameters)) )
|
77
|
+
|
78
|
+
Response.new(successful?(response), message_from(response), response,
|
79
|
+
:test => test_response?(response),
|
80
|
+
:authorization => authorization_from(response)
|
81
|
+
)
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
def successful?(response)
|
86
|
+
response[:status] == SUCCESS
|
87
|
+
end
|
88
|
+
|
89
|
+
def authorization_from(response)
|
90
|
+
[ response[:authnum], response[:transid] ].compact.join(";")
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_response?(response)
|
94
|
+
!!(response[:transid] =~ /SimProxy/)
|
95
|
+
end
|
96
|
+
|
97
|
+
def message_from(response)
|
98
|
+
successful?(response) ? SUCCESS_MESSAGE : response[:errorstring]
|
99
|
+
end
|
100
|
+
|
101
|
+
def parse(body)
|
102
|
+
response = {}
|
103
|
+
body.to_s.each_line do |l|
|
104
|
+
key, value = l.split(":", 2)
|
105
|
+
response[key.to_s.downcase.to_sym] = value.strip
|
106
|
+
end
|
107
|
+
response
|
108
|
+
end
|
109
|
+
|
110
|
+
def post_data(action, parameters = {})
|
111
|
+
parameters[:request_type] = TRANSACTIONS[action]
|
112
|
+
parameters[:merchant_id] = @options[:login]
|
113
|
+
parameters[:password] = @options[:password]
|
114
|
+
|
115
|
+
parameters.reject{|k,v| v.blank?}.collect { |key, value| "#{key.to_s.upcase}=#{CGI.escape(value.to_s)}" }.join("&")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
@@ -0,0 +1,236 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/payflow/payflow_common_api'
|
2
|
+
require File.dirname(__FILE__) + '/payflow/payflow_response'
|
3
|
+
require File.dirname(__FILE__) + '/payflow_express'
|
4
|
+
|
5
|
+
module ActiveMerchant #:nodoc:
|
6
|
+
module Billing #:nodoc:
|
7
|
+
class PayflowGateway < Gateway
|
8
|
+
include PayflowCommonAPI
|
9
|
+
|
10
|
+
RECURRING_ACTIONS = Set.new([:add, :modify, :cancel, :inquiry, :reactivate, :payment])
|
11
|
+
|
12
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :jcb, :discover, :diners_club]
|
13
|
+
self.homepage_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_payflow-pro-overview-outside'
|
14
|
+
self.display_name = 'PayPal Payflow Pro'
|
15
|
+
|
16
|
+
def authorize(money, credit_card_or_reference, options = {})
|
17
|
+
request = build_sale_or_authorization_request(:authorization, money, credit_card_or_reference, options)
|
18
|
+
|
19
|
+
commit(request)
|
20
|
+
end
|
21
|
+
|
22
|
+
def purchase(money, credit_card_or_reference, options = {})
|
23
|
+
request = build_sale_or_authorization_request(:purchase, money, credit_card_or_reference, options)
|
24
|
+
|
25
|
+
commit(request)
|
26
|
+
end
|
27
|
+
|
28
|
+
def credit(money, identification_or_credit_card, options = {})
|
29
|
+
if identification_or_credit_card.is_a?(String)
|
30
|
+
# Perform referenced credit
|
31
|
+
request = build_reference_request(:credit, money, identification_or_credit_card, options)
|
32
|
+
else
|
33
|
+
# Perform non-referenced credit
|
34
|
+
request = build_credit_card_request(:credit, money, identification_or_credit_card, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
commit(request)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Adds or modifies a recurring Payflow profile. See the Payflow Pro Recurring Billing Guide for more details:
|
41
|
+
# https://www.paypal.com/en_US/pdf/PayflowPro_RecurringBilling_Guide.pdf
|
42
|
+
#
|
43
|
+
# Several options are available to customize the recurring profile:
|
44
|
+
#
|
45
|
+
# * <tt>profile_id</tt> - is only required for editing a recurring profile
|
46
|
+
# * <tt>starting_at</tt> - takes a Date, Time, or string in mmddyyyy format. The date must be in the future.
|
47
|
+
# * <tt>name</tt> - The name of the customer to be billed. If not specified, the name from the credit card is used.
|
48
|
+
# * <tt>periodicity</tt> - The frequency that the recurring payments will occur at. Can be one of
|
49
|
+
# :bimonthly, :monthly, :biweekly, :weekly, :yearly, :daily, :semimonthly, :quadweekly, :quarterly, :semiyearly
|
50
|
+
# * <tt>payments</tt> - The term, or number of payments that will be made
|
51
|
+
# * <tt>comment</tt> - A comment associated with the profile
|
52
|
+
def recurring(money, credit_card, options = {})
|
53
|
+
options[:name] = credit_card.name if options[:name].blank? && credit_card
|
54
|
+
request = build_recurring_request(options[:profile_id] ? :modify : :add, money, options) do |xml|
|
55
|
+
add_credit_card(xml, credit_card) if credit_card
|
56
|
+
end
|
57
|
+
commit(request, :recurring)
|
58
|
+
end
|
59
|
+
|
60
|
+
def cancel_recurring(profile_id)
|
61
|
+
request = build_recurring_request(:cancel, 0, :profile_id => profile_id)
|
62
|
+
commit(request, :recurring)
|
63
|
+
end
|
64
|
+
|
65
|
+
def recurring_inquiry(profile_id, options = {})
|
66
|
+
request = build_recurring_request(:inquiry, nil, options.update( :profile_id => profile_id ))
|
67
|
+
commit(request, :recurring)
|
68
|
+
end
|
69
|
+
|
70
|
+
def express
|
71
|
+
@express ||= PayflowExpressGateway.new(@options)
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
def build_sale_or_authorization_request(action, money, credit_card_or_reference, options)
|
76
|
+
if credit_card_or_reference.is_a?(String)
|
77
|
+
build_reference_sale_or_authorization_request(action, money, credit_card_or_reference, options)
|
78
|
+
else
|
79
|
+
build_credit_card_request(action, money, credit_card_or_reference, options)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def build_reference_sale_or_authorization_request(action, money, reference, options)
|
84
|
+
xml = Builder::XmlMarkup.new
|
85
|
+
xml.tag! TRANSACTIONS[action] do
|
86
|
+
xml.tag! 'PayData' do
|
87
|
+
xml.tag! 'Invoice' do
|
88
|
+
xml.tag! 'TotalAmt', amount(money), 'Currency' => options[:currency] || currency(money)
|
89
|
+
end
|
90
|
+
xml.tag! 'Tender' do
|
91
|
+
xml.tag! 'Card' do
|
92
|
+
xml.tag! 'ExtData', 'Name' => 'ORIGID', 'Value' => reference
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
xml.target!
|
98
|
+
end
|
99
|
+
|
100
|
+
def build_credit_card_request(action, money, credit_card, options)
|
101
|
+
xml = Builder::XmlMarkup.new
|
102
|
+
xml.tag! TRANSACTIONS[action] do
|
103
|
+
xml.tag! 'PayData' do
|
104
|
+
xml.tag! 'Invoice' do
|
105
|
+
xml.tag! 'CustIP', options[:ip] unless options[:ip].blank?
|
106
|
+
xml.tag! 'InvNum', options[:order_id].to_s.gsub(/[^\w.]/, '') unless options[:order_id].blank?
|
107
|
+
xml.tag! 'Description', options[:description] unless options[:description].blank?
|
108
|
+
|
109
|
+
billing_address = options[:billing_address] || options[:address]
|
110
|
+
add_address(xml, 'BillTo', billing_address, options) if billing_address
|
111
|
+
add_address(xml, 'ShipTo', options[:shipping_address], options) if options[:shipping_address]
|
112
|
+
|
113
|
+
xml.tag! 'TotalAmt', amount(money), 'Currency' => options[:currency] || currency(money)
|
114
|
+
end
|
115
|
+
|
116
|
+
xml.tag! 'Tender' do
|
117
|
+
add_credit_card(xml, credit_card)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
xml.target!
|
122
|
+
end
|
123
|
+
|
124
|
+
def add_credit_card(xml, credit_card)
|
125
|
+
xml.tag! 'Card' do
|
126
|
+
xml.tag! 'CardType', credit_card_type(credit_card)
|
127
|
+
xml.tag! 'CardNum', credit_card.number
|
128
|
+
xml.tag! 'ExpDate', expdate(credit_card)
|
129
|
+
xml.tag! 'NameOnCard', credit_card.first_name
|
130
|
+
xml.tag! 'CVNum', credit_card.verification_value if credit_card.verification_value?
|
131
|
+
|
132
|
+
if requires_start_date_or_issue_number?(credit_card)
|
133
|
+
xml.tag!('ExtData', 'Name' => 'CardStart', 'Value' => startdate(credit_card)) unless credit_card.start_month.blank? || credit_card.start_year.blank?
|
134
|
+
xml.tag!('ExtData', 'Name' => 'CardIssue', 'Value' => format(credit_card.issue_number, :two_digits)) unless credit_card.issue_number.blank?
|
135
|
+
end
|
136
|
+
xml.tag! 'ExtData', 'Name' => 'LASTNAME', 'Value' => credit_card.last_name
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def credit_card_type(credit_card)
|
141
|
+
return '' if card_brand(credit_card).blank?
|
142
|
+
|
143
|
+
CARD_MAPPING[card_brand(credit_card).to_sym]
|
144
|
+
end
|
145
|
+
|
146
|
+
def expdate(creditcard)
|
147
|
+
year = sprintf("%.4i", creditcard.year)
|
148
|
+
month = sprintf("%.2i", creditcard.month)
|
149
|
+
|
150
|
+
"#{year}#{month}"
|
151
|
+
end
|
152
|
+
|
153
|
+
def startdate(creditcard)
|
154
|
+
year = format(creditcard.start_year, :two_digits)
|
155
|
+
month = format(creditcard.start_month, :two_digits)
|
156
|
+
|
157
|
+
"#{month}#{year}"
|
158
|
+
end
|
159
|
+
|
160
|
+
def build_recurring_request(action, money, options)
|
161
|
+
unless RECURRING_ACTIONS.include?(action)
|
162
|
+
raise StandardError, "Invalid Recurring Profile Action: #{action}"
|
163
|
+
end
|
164
|
+
|
165
|
+
xml = Builder::XmlMarkup.new
|
166
|
+
xml.tag! 'RecurringProfiles' do
|
167
|
+
xml.tag! 'RecurringProfile' do
|
168
|
+
xml.tag! action.to_s.capitalize do
|
169
|
+
unless [:cancel, :inquiry].include?(action)
|
170
|
+
xml.tag! 'RPData' do
|
171
|
+
xml.tag! 'Name', options[:name] unless options[:name].nil?
|
172
|
+
xml.tag! 'TotalAmt', amount(money), 'Currency' => options[:currency] || currency(money)
|
173
|
+
xml.tag! 'PayPeriod', get_pay_period(options)
|
174
|
+
xml.tag! 'Term', options[:payments] unless options[:payments].nil?
|
175
|
+
xml.tag! 'Comment', options[:comment] unless options[:comment].nil?
|
176
|
+
|
177
|
+
|
178
|
+
if initial_tx = options[:initial_transaction]
|
179
|
+
requires!(initial_tx, [:type, :authorization, :purchase])
|
180
|
+
requires!(initial_tx, :amount) if initial_tx[:type] == :purchase
|
181
|
+
|
182
|
+
xml.tag! 'OptionalTrans', TRANSACTIONS[initial_tx[:type]]
|
183
|
+
xml.tag! 'OptionalTransAmt', amount(initial_tx[:amount]) unless initial_tx[:amount].blank?
|
184
|
+
end
|
185
|
+
|
186
|
+
xml.tag! 'Start', format_rp_date(options[:starting_at] || Date.today + 1 )
|
187
|
+
xml.tag! 'EMail', options[:email] unless options[:email].nil?
|
188
|
+
|
189
|
+
billing_address = options[:billing_address] || options[:address]
|
190
|
+
add_address(xml, 'BillTo', billing_address, options) if billing_address
|
191
|
+
add_address(xml, 'ShipTo', options[:shipping_address], options) if options[:shipping_address]
|
192
|
+
end
|
193
|
+
xml.tag! 'Tender' do
|
194
|
+
yield xml
|
195
|
+
end
|
196
|
+
end
|
197
|
+
if action != :add
|
198
|
+
xml.tag! "ProfileID", options[:profile_id]
|
199
|
+
end
|
200
|
+
if action == :inquiry
|
201
|
+
xml.tag! "PaymentHistory", ( options[:history] ? 'Y' : 'N' )
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def get_pay_period(options)
|
209
|
+
requires!(options, [:periodicity, :bimonthly, :monthly, :biweekly, :weekly, :yearly, :daily, :semimonthly, :quadweekly, :quarterly, :semiyearly])
|
210
|
+
case options[:periodicity]
|
211
|
+
when :weekly then 'Weekly'
|
212
|
+
when :biweekly then 'Bi-weekly'
|
213
|
+
when :semimonthly then 'Semi-monthly'
|
214
|
+
when :quadweekly then 'Every four weeks'
|
215
|
+
when :monthly then 'Monthly'
|
216
|
+
when :quarterly then 'Quarterly'
|
217
|
+
when :semiyearly then 'Semi-yearly'
|
218
|
+
when :yearly then 'Yearly'
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def format_rp_date(time)
|
223
|
+
case time
|
224
|
+
when Time, Date then time.strftime("%m%d%Y")
|
225
|
+
else
|
226
|
+
time.to_s
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
def build_response(success, message, response, options = {})
|
231
|
+
PayflowResponse.new(success, message, response, options)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
@@ -0,0 +1,207 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
module PayflowCommonAPI
|
4
|
+
def self.included(base)
|
5
|
+
base.default_currency = 'USD'
|
6
|
+
|
7
|
+
base.class_inheritable_accessor :partner
|
8
|
+
|
9
|
+
# Set the default partner to PayPal
|
10
|
+
base.partner = 'PayPal'
|
11
|
+
|
12
|
+
base.supported_countries = ['US', 'CA', 'SG', 'AU']
|
13
|
+
|
14
|
+
base.class_inheritable_accessor :timeout
|
15
|
+
base.timeout = 60
|
16
|
+
|
17
|
+
# Enable safe retry of failed connections
|
18
|
+
# Payflow is safe to retry because retried transactions use the same
|
19
|
+
# X-VPS-Request-ID header. If a transaction is detected as a duplicate
|
20
|
+
# only the original transaction data will be used by Payflow, and the
|
21
|
+
# subsequent Responses will have a :duplicate parameter set in the params
|
22
|
+
# hash.
|
23
|
+
base.retry_safe = true
|
24
|
+
end
|
25
|
+
|
26
|
+
XMLNS = 'http://www.paypal.com/XMLPay'
|
27
|
+
TEST_URL = 'https://pilot-payflowpro.paypal.com'
|
28
|
+
LIVE_URL = 'https://payflowpro.paypal.com'
|
29
|
+
|
30
|
+
CARD_MAPPING = {
|
31
|
+
:visa => 'Visa',
|
32
|
+
:master => 'MasterCard',
|
33
|
+
:discover => 'Discover',
|
34
|
+
:american_express => 'Amex',
|
35
|
+
:jcb => 'JCB',
|
36
|
+
:diners_club => 'DinersClub',
|
37
|
+
:switch => 'Switch',
|
38
|
+
:solo => 'Solo'
|
39
|
+
}
|
40
|
+
|
41
|
+
TRANSACTIONS = {
|
42
|
+
:purchase => "Sale",
|
43
|
+
:authorization => "Authorization",
|
44
|
+
:capture => "Capture",
|
45
|
+
:void => "Void",
|
46
|
+
:credit => "Credit"
|
47
|
+
}
|
48
|
+
|
49
|
+
CVV_CODE = {
|
50
|
+
'Match' => 'M',
|
51
|
+
'No Match' => 'N',
|
52
|
+
'Service Not Available' => 'U',
|
53
|
+
'Service not Requested' => 'P'
|
54
|
+
}
|
55
|
+
|
56
|
+
def initialize(options = {})
|
57
|
+
requires!(options, :login, :password)
|
58
|
+
|
59
|
+
@options = options
|
60
|
+
@options[:partner] = partner if @options[:partner].blank?
|
61
|
+
super
|
62
|
+
end
|
63
|
+
|
64
|
+
def test?
|
65
|
+
@options[:test] || super
|
66
|
+
end
|
67
|
+
|
68
|
+
def capture(money, authorization, options = {})
|
69
|
+
request = build_reference_request(:capture, money, authorization, options)
|
70
|
+
commit(request)
|
71
|
+
end
|
72
|
+
|
73
|
+
def void(authorization, options = {})
|
74
|
+
request = build_reference_request(:void, nil, authorization, options)
|
75
|
+
commit(request)
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
def build_request(body, request_type = nil)
|
80
|
+
xml = Builder::XmlMarkup.new
|
81
|
+
xml.instruct!
|
82
|
+
xml.tag! 'XMLPayRequest', 'Timeout' => 30, 'version' => "2.1", "xmlns" => XMLNS do
|
83
|
+
xml.tag! 'RequestData' do
|
84
|
+
xml.tag! 'Vendor', @options[:login]
|
85
|
+
xml.tag! 'Partner', @options[:partner]
|
86
|
+
if request_type == :recurring
|
87
|
+
xml << body
|
88
|
+
else
|
89
|
+
xml.tag! 'Transactions' do
|
90
|
+
xml.tag! 'Transaction' do
|
91
|
+
xml.tag! 'Verbosity', 'MEDIUM'
|
92
|
+
xml << body
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
xml.tag! 'RequestAuth' do
|
98
|
+
xml.tag! 'UserPass' do
|
99
|
+
xml.tag! 'User', !@options[:user].blank? ? @options[:user] : @options[:login]
|
100
|
+
xml.tag! 'Password', @options[:password]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
xml.target!
|
105
|
+
end
|
106
|
+
|
107
|
+
def build_reference_request(action, money, authorization, options)
|
108
|
+
xml = Builder::XmlMarkup.new
|
109
|
+
xml.tag! TRANSACTIONS[action] do
|
110
|
+
xml.tag! 'PNRef', authorization
|
111
|
+
|
112
|
+
unless money.nil?
|
113
|
+
xml.tag! 'Invoice' do
|
114
|
+
xml.tag! 'TotalAmt', amount(money), 'Currency' => options[:currency] || currency(money)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
xml.target!
|
120
|
+
end
|
121
|
+
|
122
|
+
def add_address(xml, tag, address, options)
|
123
|
+
return if address.nil?
|
124
|
+
xml.tag! tag do
|
125
|
+
xml.tag! 'Name', address[:name] unless address[:name].blank?
|
126
|
+
xml.tag! 'EMail', options[:email] unless options[:email].blank?
|
127
|
+
xml.tag! 'Phone', address[:phone] unless address[:phone].blank?
|
128
|
+
xml.tag! 'CustCode', options[:customer] if !options[:customer].blank? && tag == 'BillTo'
|
129
|
+
|
130
|
+
xml.tag! 'Address' do
|
131
|
+
xml.tag! 'Street', address[:address1] unless address[:address1].blank?
|
132
|
+
xml.tag! 'City', address[:city] unless address[:city].blank?
|
133
|
+
xml.tag! 'State', address[:state].blank? ? "N/A" : address[:state]
|
134
|
+
xml.tag! 'Country', address[:country] unless address[:country].blank?
|
135
|
+
xml.tag! 'Zip', address[:zip] unless address[:zip].blank?
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def parse(data)
|
141
|
+
response = {}
|
142
|
+
xml = REXML::Document.new(data)
|
143
|
+
root = REXML::XPath.first(xml, "//ResponseData")
|
144
|
+
|
145
|
+
# REXML::XPath in Ruby 1.8.6 is now unable to match nodes based on their attributes
|
146
|
+
tx_result = REXML::XPath.first(root, "//TransactionResult")
|
147
|
+
|
148
|
+
if tx_result && tx_result.attributes['Duplicate'] == "true"
|
149
|
+
response[:duplicate] = true
|
150
|
+
end
|
151
|
+
|
152
|
+
root.elements.to_a.each do |node|
|
153
|
+
parse_element(response, node)
|
154
|
+
end
|
155
|
+
|
156
|
+
response
|
157
|
+
end
|
158
|
+
|
159
|
+
def parse_element(response, node)
|
160
|
+
node_name = node.name.underscore.to_sym
|
161
|
+
case
|
162
|
+
when node_name == :rp_payment_result
|
163
|
+
# Since we'll have multiple history items, we can't just flatten everything
|
164
|
+
# down as we do everywhere else. RPPaymentResult elements are not contained
|
165
|
+
# in an RPPaymentResults element so we'll come here multiple times
|
166
|
+
response[node_name] ||= []
|
167
|
+
response[node_name] << ( payment_result_response = {} )
|
168
|
+
node.elements.each{ |e| parse_element(payment_result_response, e) }
|
169
|
+
when node.has_elements?
|
170
|
+
node.elements.each{|e| parse_element(response, e) }
|
171
|
+
when node_name.to_s =~ /amt$/
|
172
|
+
# *Amt elements don't put the value in the #text - instead they use a Currency attribute
|
173
|
+
response[node_name] = node.attributes['Currency']
|
174
|
+
when node_name == :ext_data
|
175
|
+
response[node.attributes['Name'].underscore.to_sym] = node.attributes['Value']
|
176
|
+
else
|
177
|
+
response[node_name] = node.text
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def build_headers(content_length)
|
182
|
+
{
|
183
|
+
"Content-Type" => "text/xml",
|
184
|
+
"Content-Length" => content_length.to_s,
|
185
|
+
"X-VPS-Client-Timeout" => timeout.to_s,
|
186
|
+
"X-VPS-VIT-Integration-Product" => "ActiveMerchant",
|
187
|
+
"X-VPS-VIT-Runtime-Version" => RUBY_VERSION,
|
188
|
+
"X-VPS-Request-ID" => Utils.generate_unique_id
|
189
|
+
}
|
190
|
+
end
|
191
|
+
|
192
|
+
def commit(request_body, request_type = nil)
|
193
|
+
request = build_request(request_body, request_type)
|
194
|
+
headers = build_headers(request.size)
|
195
|
+
|
196
|
+
response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, request, headers))
|
197
|
+
|
198
|
+
build_response(response[:result] == "0", response[:message], response,
|
199
|
+
:test => test?,
|
200
|
+
:authorization => response[:pn_ref] || response[:rp_ref],
|
201
|
+
:cvv_result => CVV_CODE[response[:cv_result]],
|
202
|
+
:avs_result => { :code => response[:avs_result] }
|
203
|
+
)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|