figpay_gateway 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,54 @@
1
+ module NMIGateway
2
+ class Recurring < Api
3
+
4
+ # NMIGateway::Recurring.new.create_plan plan_amount: 1.99, plan_name: "Test 1.99", plan_id: "test-1", month_frequency: 1, day_of_month: 1
5
+ def create_plan(options = {})
6
+ query = set_query(options)
7
+ query[:recurring] = 'add_plan'
8
+ query[:type] = 'recurring'
9
+ query[:plan_payments] ||= '0'
10
+ require_fields(:plan_amount, :plan_name, :plan_id)
11
+ post query
12
+ end
13
+
14
+
15
+ # NMIGateway::Recurring.new.add_subscription_to_plan plan_id: "test-1", customer_vault_id: 664625840
16
+ def add_subscription_to_plan(options = {})
17
+ query = set_query(options)
18
+ query[:recurring] = 'add_subscription'
19
+ query[:type] = 'recurring'
20
+ require_fields(:plan_id)
21
+ post query
22
+ end
23
+
24
+ # NMIGateway::Recurring.new.add_custom_subscription plan_amount: 1.99, month_frequency: 1, day_of_month: 1, customer_vault_id: 664625840
25
+ def add_custom_subscription(options = {})
26
+ query = set_query(options)
27
+ query[:recurring] = 'add_subscription'
28
+ query[:type] = 'recurring'
29
+ query[:plan_payments] ||= '0'
30
+ require_fields(:plan_payments, :plan_amount)
31
+ post query
32
+ end
33
+
34
+ # NMIGateway::Recurring.new.update_subscription subscription_id: "3261766445", first_name: "John", last_name: "Doe"
35
+ def update_subscription(options = {})
36
+ query = set_query(options)
37
+ query[:recurring] = 'update_subscription'
38
+ query[:type] = 'recurring'
39
+ require_fields(:subscription_id)
40
+ post query
41
+ end
42
+
43
+ # NMIGateway::Recurring.new.delete_subscription subscription_id: "3261766445"
44
+ def delete_subscription(options = {})
45
+ query = set_query(options)
46
+ query[:recurring] = 'delete_subscription'
47
+ query[:type] = 'recurring'
48
+ require_fields(:subscription_id)
49
+ post query
50
+ end
51
+
52
+ end
53
+ end
54
+
@@ -0,0 +1,175 @@
1
+ module NMIGateway
2
+ class Response
3
+
4
+ attr_accessor :response, :success, :code, :api_type, :transactions, :customers, :response_text, :response_message, :customer_vault_id, :subscription_id, :plan_id, :plan_amount, :orderid, :transactionid, :authcode, :response_code
5
+
6
+ def initialize(response, api_type)
7
+ @response = response
8
+ @code = response.code
9
+ @api_type = api_type
10
+ @success = response.success?
11
+ send "set_#{api_type}"
12
+ end
13
+
14
+ def set_
15
+ parsed_response
16
+ binding.pry
17
+ end
18
+
19
+ def success?
20
+ !!success
21
+ end
22
+
23
+ private
24
+
25
+ def parsed_response
26
+ if response.body.is_a?(String)
27
+ if response.body.include?('xml')
28
+ Hash.from_xml response.body
29
+ else
30
+ parsed = CGI.parse(response.body)
31
+ @response_message = responses[parsed['response'].first]
32
+ @success = parsed['response'].first == '1'
33
+ @response_text = parsed['responsetext'].first
34
+ @response_code = parsed['response_code'].first if parsed['response_code'].first.present?
35
+ @authcode = parsed['authcode'].first if parsed['authcode'].first.present?
36
+ @customer_vault_id = parsed['customer_vault_id'].first if parsed['customer_vault_id'].first.present?
37
+ @plan_id = parsed['plan_id'].first if parsed['plan_id'].first.present?
38
+ @plan_amount = parsed['plan_amount'].first if parsed['plan_amount'].first.present?
39
+ @subscription_id = parsed['subscription_id'].first if parsed['subscription_id'].first.present?
40
+ @orderid = parsed['orderid'].first if parsed['orderid'].first.present?
41
+ @transactionid = parsed['transactionid'].first if parsed['transactionid'].first.present?
42
+ parsed
43
+ end
44
+ else
45
+ response
46
+ end
47
+ end
48
+
49
+
50
+ def set_transaction
51
+ parsed_response
52
+ if parsed_response && parsed_response['nm_response'].present? && parsed_response['nm_response']['transaction'].present?
53
+ transactions = parsed_response['nm_response']['transaction']
54
+ if transactions.is_a?(Hash)
55
+ @transactions = [ NMIGateway::Result::Transaction.new( transactions ) ]
56
+ elsif transactions.is_a?(Array)
57
+ @transactions = transactions.map {|c| NMIGateway::Result::Transaction.new( c ) }
58
+ end
59
+ else
60
+ self
61
+ end
62
+ end
63
+ alias_method :set_sale, :set_transaction
64
+ alias_method :set_auth, :set_transaction
65
+ alias_method :set_credit, :set_transaction
66
+ alias_method :set_validate, :set_transaction
67
+ alias_method :set_capture, :set_transaction
68
+ alias_method :set_void, :set_transaction
69
+ alias_method :set_refund, :set_transaction
70
+ alias_method :set_update, :set_transaction
71
+
72
+ def set_customer
73
+ parsed_response
74
+ end
75
+ alias_method :set_add_customer, :set_customer
76
+ alias_method :set_update_customer, :set_customer
77
+ alias_method :set_delete_customer, :set_customer
78
+
79
+ # def set_receipt
80
+ # parsed_response
81
+ # end
82
+
83
+ def set_recurring
84
+ parsed_response
85
+ end
86
+
87
+ def set_customer_vault
88
+ parsed_response
89
+ if parsed_response && parsed_response['nm_response'] && parsed_response['nm_response']['customer_vault'] && customers = parsed_response['nm_response']['customer_vault']['customer']
90
+ if customers.is_a?(Hash)
91
+ @customers = [ NMIGateway::Result::Customer.new( customers ) ]
92
+ elsif customers.is_a?(Array)
93
+ @customers = customers.map {|c| NMIGateway::Result::Customer.new( c ) }
94
+ end
95
+ end
96
+ end
97
+
98
+ def responses
99
+ {"1" => "Transaction Approved", "2" => "Transaction Declined", "3" => "Error in transaction data or system error"}
100
+ end
101
+
102
+ def response_codes
103
+ {
104
+ "100" => "Transaction was approved.",
105
+ "200" => "Transaction was declined by processor.",
106
+ "201" => "Do not honor.",
107
+ "202" => "Insufficient funds.",
108
+ "203" => "Over limit.",
109
+ "204" => "Transaction not allowed.",
110
+ "220" => "Incorrect payment information.",
111
+ "221" => "No such card issuer.",
112
+ "222" => "No card number on file with issuer.",
113
+ "223" => "Expired card.",
114
+ "224" => "Invalid expiration date.",
115
+ "225" => "Invalid card security code.",
116
+ "240" => "Call issuer for further information.",
117
+ "250" => "Pick up card.",
118
+ "251" => "Lost card.",
119
+ "252" => "Stolen card.",
120
+ "253" => "Fraudulent card.",
121
+ "260" => "Declined with further instructions available. (See response text)",
122
+ "261" => "Declined-Stop all recurring payments.",
123
+ "262" => "Declined-Stop this recurring program.",
124
+ "263" => "Declined-Update cardholder data available.",
125
+ "264" => "Declined-Retry in a few days.",
126
+ "300" => "Transaction was rejected by gateway.",
127
+ "400" => "Transaction error returned by processor.",
128
+ "410" => "Invalid merchant configuration.",
129
+ "411" => "Merchant account is inactive.",
130
+ "420" => "Communication error.",
131
+ "421" => "Communication error with issuer.",
132
+ "430" => "Duplicate transaction at processor.",
133
+ "440" => "Processor format error.",
134
+ "441" => "Invalid transaction information.",
135
+ "460" => "Processor feature not available.",
136
+ "461" => "Unsupported card type."
137
+ }
138
+ end
139
+
140
+ def avs_response_codes
141
+ {
142
+ "X" => "Exact match, 9-character numeric ZIP",
143
+ "Y" => "Exact match, 5-character numeric ZIP",
144
+ "D" => "Exact match, 5-character numeric ZIP",
145
+ "M" => "Exact match, 5-character numeric ZIP",
146
+ "A" => "Address match only",
147
+ "B" => "Address match only",
148
+ "W" => "9-character numeric ZIP match only",
149
+ "Z" => "5-character ZIP match only",
150
+ "P" => "5-character ZIP match only",
151
+ "L" => "5-character ZIP match only",
152
+ "N" => "No address or ZIP match only",
153
+ "C" => "No address or ZIP match only",
154
+ "U" => "Address unavailable",
155
+ "G" => "Non-U.S. issuer does not participate",
156
+ "I" => "Non-U.S. issuer does not participate",
157
+ "R" => "Issuer system unavailable",
158
+ "E" => "Not a mail/phone order",
159
+ "S" => "Service not supported",
160
+ "O" => "AVS not available"
161
+ }
162
+ end
163
+
164
+ def cvv_response_codes
165
+ {
166
+ "M" => "CVV2/CVC2 match",
167
+ "N" => "CVV2/CVC2 no match",
168
+ "P" => "Not processed",
169
+ "S" => "Merchant has indicated that CVV2/CVC2 is not present on card",
170
+ "U" => "Issuer is not certified and/or has not provided Visa encryption keys"
171
+ }
172
+ end
173
+
174
+ end
175
+ end
@@ -0,0 +1,38 @@
1
+ module NMIGateway
2
+ module Result
3
+ class Action < Data
4
+
5
+ attr_accessor :amount, :action_type, :date, :success, :ip_address, :source, :username, :response_text, :batch_id, :processor_batch_id, :response_code, :processor_response_text, :processor_response_code, :device_license_number, :device_nickname
6
+
7
+ attr_accessor
8
+
9
+ def initialize(action)
10
+ set_attributes(action)
11
+ $actions ||= []
12
+ $actions << action.keys
13
+ end
14
+
15
+ private
16
+
17
+ def set_attributes(action)
18
+ @amount = action["amount"]
19
+ @action_type = action["action_type"]
20
+ @date = action["date"]
21
+ @success = action["success"]
22
+ @ip_address = action["ip_address"]
23
+ @source = action["source"]
24
+ @username = action["username"]
25
+ @response_text = action["response_text"]
26
+ @batch_id = action["batch_id"]
27
+ @processor_batch_id = action["processor_batch_id"]
28
+ @response_code = action["response_code"]
29
+ @processor_response_text = action["processor_response_text"]
30
+ @processor_response_code = action["processor_response_code"]
31
+ @device_license_number = action["device_license_number"]
32
+ @device_nickname = action["device_nickname"]
33
+
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,63 @@
1
+ module NMIGateway
2
+ module Result
3
+ class Customer < Data
4
+
5
+ attr_accessor :id, :first_name, :last_name, :address_1, :address_2, :company, :city, :state, :postal_code, :country, :email, :phone, :fax, :cell_phone, :customertaxid, :website, :shipping_first_name, :shipping_last_name, :shipping_address_1, :shipping_address_2, :shipping_company, :shipping_city, :shipping_state, :shipping_postal_code, :shipping_country, :shipping_email, :shipping_carrier, :tracking_number, :shipping_date, :shipping, :cc_number, :cc_hash, :cc_exp, :cc_start_date, :cc_issue_number, :check_account, :check_hash, :check_aba, :check_name, :account_holder_type, :account_type, :sec_code, :processor_id, :cc_bin, :customer_vault_id
6
+
7
+
8
+ def initialize(customer)
9
+ set_attributes(customer)
10
+ end
11
+
12
+ private
13
+ def set_attributes(customer)
14
+ @id = customer["id"]
15
+ @first_name = customer["first_name"]
16
+ @last_name = customer["last_name"]
17
+ @address_1 = customer["address_1"]
18
+ @address_2 = customer["address_2"]
19
+ @company = customer["company"]
20
+ @city = customer["city"]
21
+ @state = customer["state"]
22
+ @postal_code = customer["postal_code"]
23
+ @country = customer["country"]
24
+ @email = customer["email"]
25
+ @phone = customer["phone"]
26
+ @fax = customer["fax"]
27
+ @cell_phone = customer["cell_phone"]
28
+ @customertaxid = customer["customertaxid"]
29
+ @website = customer["website"]
30
+ @shipping_first_name = customer["shipping_first_name"]
31
+ @shipping_last_name = customer["shipping_last_name"]
32
+ @shipping_address_1 = customer["shipping_address_1"]
33
+ @shipping_address_2 = customer["shipping_address_2"]
34
+ @shipping_company = customer["shipping_company"]
35
+ @shipping_city = customer["shipping_city"]
36
+ @shipping_state = customer["shipping_state"]
37
+ @shipping_postal_code = customer["shipping_postal_code"]
38
+ @shipping_country = customer["shipping_country"]
39
+ @shipping_email = customer["shipping_email"]
40
+ @shipping_carrier = customer["shipping_carrier"]
41
+ @tracking_number = customer["tracking_number"]
42
+ @shipping_date = customer["shipping_date"]
43
+ @shipping = customer["shipping"]
44
+ @cc_number = customer["cc_number"]
45
+ @cc_hash = customer["cc_hash"]
46
+ @cc_exp = customer["cc_exp"]
47
+ @cc_start_date = customer["cc_start_date"]
48
+ @cc_issue_number = customer["cc_issue_number"]
49
+ @check_account = customer["check_account"]
50
+ @check_hash = customer["check_hash"]
51
+ @check_aba = customer["check_aba"]
52
+ @check_name = customer["check_name"]
53
+ @account_holder_type = customer["account_holder_type"]
54
+ @account_type = customer["account_type"]
55
+ @sec_code = customer["sec_code"]
56
+ @processor_id = customer["processor_id"]
57
+ @cc_bin = customer["cc_bin"]
58
+ @customer_vault_id = customer["customer_vault_id"]
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,74 @@
1
+
2
+
3
+ module NMIGateway
4
+ module Result
5
+ class Transaction < Data
6
+
7
+ attr_accessor :transaction_id, :partial_payment_id, :partial_payment_balance, :platform_id, :transaction_type, :condition, :order_id, :authorization_code, :ponumber, :order_description, :first_name, :last_name, :address_1, :address_2, :company, :city, :state, :postal_code, :country, :email, :phone, :fax, :cell_phone, :customertaxid, :customerid, :website, :shipping_first_name, :shipping_last_name, :shipping_address_1, :shipping_address_2, :shipping_company, :shipping_city, :shipping_state, :shipping_postal_code, :shipping_country, :shipping_email, :shipping_carrier, :tracking_number, :shipping_date, :shipping, :shipping_phone, :cc_number, :cc_hash, :cc_exp, :cavv, :actions
8
+
9
+ def initialize(transaction)
10
+ set_attributes(transaction)
11
+ end
12
+
13
+ private
14
+
15
+ def set_attributes(transaction)
16
+ @transaction_id = transaction["transaction_id"]
17
+ @partial_payment_id = transaction["partial_payment_id"]
18
+ @partial_payment_balance = transaction["partial_payment_balance"]
19
+ @platform_id = transaction["platform_id"]
20
+ @transaction_type = transaction["transaction_type"]
21
+ @condition = transaction["condition"]
22
+ @order_id = transaction["order_id"]
23
+ @authorization_code = transaction["authorization_code"]
24
+ @ponumber = transaction["ponumber"]
25
+ @order_description = transaction["order_description"]
26
+ @first_name = transaction["first_name"]
27
+ @last_name = transaction["last_name"]
28
+ @address_1 = transaction["address_1"]
29
+ @address_2 = transaction["address_2"]
30
+ @company = transaction["company"]
31
+ @city = transaction["city"]
32
+ @state = transaction["state"]
33
+ @postal_code = transaction["postal_code"]
34
+ @country = transaction["country"]
35
+ @email = transaction["email"]
36
+ @phone = transaction["phone"]
37
+ @fax = transaction["fax"]
38
+ @cell_phone = transaction["cell_phone"]
39
+ @customertaxid = transaction["customertaxid"]
40
+ @customerid = transaction["customerid"]
41
+ @website = transaction["website"]
42
+ @shipping_first_name = transaction["shipping_first_name"]
43
+ @shipping_last_name = transaction["shipping_last_name"]
44
+ @shipping_address_1 = transaction["shipping_address_1"]
45
+ @shipping_address_2 = transaction["shipping_address_2"]
46
+ @shipping_company = transaction["shipping_company"]
47
+ @shipping_city = transaction["shipping_city"]
48
+ @shipping_state = transaction["shipping_state"]
49
+ @shipping_postal_code = transaction["shipping_postal_code"]
50
+ @shipping_country = transaction["shipping_country"]
51
+ @shipping_email = transaction["shipping_email"]
52
+ @shipping_carrier = transaction["shipping_carrier"]
53
+ @tracking_number = transaction["tracking_number"]
54
+ @shipping_date = transaction["shipping_date"]
55
+ @shipping = transaction["shipping"]
56
+ @shipping_phone = transaction["shipping_phone"]
57
+ @cc_number = transaction["cc_number"]
58
+ @cc_hash = transaction["cc_hash"]
59
+ @cc_exp = transaction["cc_exp"]
60
+ @cavv = transaction["cavv"]
61
+ set_actions(transaction["action"])
62
+ end
63
+
64
+ def set_actions(actions)
65
+ if actions.is_a?(Hash)
66
+ @actions = [ NMIGateway::Result::Action.new( actions ) ]
67
+ elsif actions.is_a?(Array)
68
+ @actions = actions.map {|c| NMIGateway::Result::Action.new( c ) }
69
+ end if actions.present?
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,110 @@
1
+ module NMIGateway
2
+ class Transaction < Api
3
+
4
+ # NMIGateway::Transaction.new.sale ccnumber: '4111111111111111', ccexp: "0219", first_name: "John", last_name: "Doe", amount: 22.30, email: "john@doe.com", country: "US"
5
+ # NMIGateway::Transaction.new.sale payment_token: 'abc123', first_name: "John", last_name: "Doe", amount: 22.30, email: "john@doe.com", country: "US"
6
+ # NMIGateway::Transaction.new.sale customer_vault_id: '123456789', amount: 22.30
7
+ def sale(options = {})
8
+ query = set_query(options)
9
+ query[:type] = 'sale'
10
+ if query[:customer_vault_id]
11
+ require_fields(:customer_vault_id, :amount)
12
+ elsif query[:payment_token]
13
+ require_fields(:payment_token, :first_name, :last_name, :email, :amount)
14
+ else
15
+ require_fields(:ccnumber, :ccexp, :first_name, :last_name, :email, :amount)
16
+ end
17
+ post query
18
+ end
19
+
20
+ # NMIGateway::Transaction.new.authorize ccnumber: '4111111111111111', ccexp: "0219", first_name: "John", last_name: "Doe", amount: 22.25, email: "john@doe.com", country: "US"
21
+ # NMIGateway::Transaction.new.authorize payment_token: 'abc123', first_name: "John", last_name: "Doe", amount: 22.25, email: "john@doe.com", country: "US"
22
+ # NMIGateway::Transaction.new.authorize customer_vault_id: '123456789', amount: 22.25
23
+ def authorize(options = {})
24
+ query = set_query(options)
25
+ query[:type] = 'auth'
26
+ if query[:customer_vault_id]
27
+ require_fields(:customer_vault_id, :amount)
28
+ elsif query[:payment_token]
29
+ require_fields(:payment_token, :first_name, :last_name, :email, :amount)
30
+ else
31
+ require_fields(:ccnumber, :ccexp, :first_name, :last_name, :email, :amount)
32
+ end
33
+ post query
34
+ end
35
+
36
+ # NMIGateway::Transaction.new.capture transactionid: 3261830498, amount: 22.30
37
+ def capture(options = {})
38
+ query = set_query(options)
39
+ query[:type] = 'capture'
40
+ require_fields(:transactionid, :amount )
41
+ post query
42
+ end
43
+
44
+ # NMIGateway::Transaction.new.void transactionid: 3261830498, amount: 22.30
45
+ def void(options = {})
46
+ query = set_query(options)
47
+ query[:type] = 'void'
48
+ require_fields(:transactionid)
49
+ post query
50
+ end
51
+
52
+ # NMIGateway::Transaction.new.refund transactionid: 3261844010, amount: 5
53
+ def refund(options = {})
54
+ query = set_query(options)
55
+ query[:type] = 'refund'
56
+ require_fields(:transactionid) # amount
57
+ post query
58
+ end
59
+
60
+ # NMIGateway::Transaction.new.update transactionid: 3261844010, first_name: "joe"
61
+ def update(options = {})
62
+ query = set_query(options)
63
+ query[:type] = 'update'
64
+ require_fields(:transactionid)
65
+ post query
66
+ end
67
+
68
+ # NMIGateway::Transaction.new.find transactionid: 3261844010
69
+ def find(options = {})
70
+ query = set_query(options)
71
+ query[:report_type] ||= 'transaction'
72
+ get query
73
+ end
74
+
75
+ # Disabled for our merchant account
76
+ # NMIGateway::Transaction.new.credit ccnumber: '4111111111111111', ccexp: "0219", first_name: "John", last_name: "Doe", amount: 22.30, email: "john@doe.com", country: "US"
77
+ # NMIGateway::Transaction.new.credit payment_token: 'abc123', first_name: "John", last_name: "Doe", amount: 22.30, email: "john@doe.com", country: "US"
78
+ # NMIGateway::Transaction.new.credit customer_vault_id: '123456789', amount: 22.30
79
+ def credit(options = {})
80
+ query = set_query(options)
81
+ query[:type] = 'credit'
82
+ if query[:customer_vault_id]
83
+ require_fields(:customer_vault_id, :amount)
84
+ elsif query[:payment_token]
85
+ require_fields(:payment_token, :first_name, :last_name, :email, :amount)
86
+ else
87
+ require_fields(:ccnumber, :ccexp, :first_name, :last_name, :email, :amount)
88
+ end
89
+ post query
90
+ end
91
+
92
+ # Disabled for our merchant account
93
+ # NMIGateway::Transaction.new.validate ccnumber: '4111111111111111', ccexp: "0219", first_name: "John", last_name: "Doe", email: "john@doe.com", country: "US"
94
+ # NMIGateway::Transaction.new.validate payment_token: 'abc123', first_name: "John", last_name: "Doe", email: "john@doe.com", country: "US"
95
+ # NMIGateway::Transaction.new.validate customer_vault_id: '123456789'
96
+ def validate(options = {})
97
+ query = set_query(options)
98
+ query[:type] = 'validate'
99
+ if query[:customer_vault_id]
100
+ require_fields(:customer_vault_id)
101
+ elsif query[:payment_token]
102
+ require_fields(:payment_token, :first_name, :last_name, :email)
103
+ else
104
+ require_fields(:ccnumber, :ccexp, :first_name, :last_name, :email)
105
+ end
106
+ post query
107
+ end
108
+
109
+ end
110
+ end
@@ -0,0 +1,29 @@
1
+ require "rubygems"
2
+ require "active_support/all"
3
+ require "httparty"
4
+ require "ostruct"
5
+
6
+ require "figpay_gateway/version"
7
+
8
+ require "nmi_gateway/api"
9
+ require "nmi_gateway/data"
10
+ require "nmi_gateway/result/action"
11
+ require "nmi_gateway/result/transaction"
12
+ require "nmi_gateway/result/customer"
13
+ require "nmi_gateway/customer_vault"
14
+
15
+ require "nmi_gateway/error"
16
+ require "nmi_gateway/recurring"
17
+ require "nmi_gateway/response"
18
+ require "nmi_gateway/transaction"
19
+
20
+ module FigpayGateway
21
+ # Expose NMIGateway classes under the FigpayGateway namespace
22
+ Api = NMIGateway::Api
23
+ Transaction = NMIGateway::Transaction
24
+ CustomerVault = NMIGateway::CustomerVault
25
+ Recurring = NMIGateway::Recurring
26
+ Response = NMIGateway::Response
27
+ Error = NMIGateway::Error
28
+ Data = NMIGateway::Data
29
+ end