Class: ATPAY::Payment
Instance Attribute Summary collapse
-
#account_id ⇒ Object
Returns the value of attribute account_id.
-
#address ⇒ Object
Returns the value of attribute address.
-
#address2 ⇒ Object
Returns the value of attribute address2.
-
#amount ⇒ Object
charge info.
-
#atpay_error ⇒ Object
internal.
-
#base_amount ⇒ Object
Returns the value of attribute base_amount.
-
#city ⇒ Object
Returns the value of attribute city.
-
#credit_card_type ⇒ Object
Returns the value of attribute credit_card_type.
-
#cvv ⇒ Object
Returns the value of attribute cvv.
-
#dynamic_tags ⇒ Object
internal.
-
#email ⇒ Object
Returns the value of attribute email.
-
#error ⇒ Object
internal.
-
#error_id ⇒ Object
internal.
-
#errors ⇒ Object
internal.
-
#expiration_date ⇒ Object
Returns the value of attribute expiration_date.
-
#first_installment_amount ⇒ Object
Returns the value of attribute first_installment_amount.
-
#first_installment_interval ⇒ Object
Returns the value of attribute first_installment_interval.
-
#first_name ⇒ Object
user info.
-
#free_text ⇒ Object
Returns the value of attribute free_text.
-
#host ⇒ Object
Returns the value of attribute host.
-
#initial_pre_auth_amount ⇒ Object
Returns the value of attribute initial_pre_auth_amount.
-
#ip_address ⇒ Object
Returns the value of attribute ip_address.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#name_on_card ⇒ Object
card info.
-
#number ⇒ Object
Returns the value of attribute number.
-
#order_id ⇒ Object
Returns the value of attribute order_id.
-
#org_options ⇒ Object
internal.
-
#password ⇒ Object
Returns the value of attribute password.
-
#phone ⇒ Object
Returns the value of attribute phone.
-
#recurring_amount ⇒ Object
Returns the value of attribute recurring_amount.
-
#recurring_installment_interval_method ⇒ Object
Returns the value of attribute recurring_installment_interval_method.
-
#recurring_installment_interval_method_additional_info ⇒ Object
Returns the value of attribute recurring_installment_interval_method_additional_info.
-
#recurring_payment ⇒ Object
recurrring info.
-
#request ⇒ Object
results.
-
#response ⇒ Object
Returns the value of attribute response.
-
#response_code ⇒ Object
internal.
-
#service_expiry_method ⇒ Object
Returns the value of attribute service_expiry_method.
-
#service_expiry_method_additional_info ⇒ Object
Returns the value of attribute service_expiry_method_additional_info.
-
#state ⇒ Object
Returns the value of attribute state.
-
#sub_account_id ⇒ Object
Returns the value of attribute sub_account_id.
-
#success ⇒ Object
Returns the value of attribute success.
-
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
-
#username ⇒ Object
Returns the value of attribute username.
-
#xml ⇒ Object
internal.
-
#zip ⇒ Object
Returns the value of attribute zip.
Instance Method Summary collapse
- #charge(options = {}) ⇒ Object
- #fire_payment_request ⇒ Object
- #handle_payment_response ⇒ Object
-
#initialize ⇒ Payment
constructor
A new instance of Payment.
- #render_xml ⇒ Object
- #send_payment_request ⇒ Object
- #soap_action ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize ⇒ Payment
Returns a new instance of Payment.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/atpay/payment.rb', line 55 def initialize @username = ATPAY.username @password = ATPAY.password @host = ATPAY.host @ip_address = '127.0.0.1' @error = @first_name = @last_name = @email = @address = @address2 = @city = @state = @zip = @phone = @name_on_card = @number = @credit_card_type = @cvv = @expiration_date = @free_text = @recurring_installment_interval_method_additional_info = @account_id = @sub_account_id = @service_expiry_method = @service_expiry_method_additional_info = @request = @response = @transaction_id = @org_options = @dynamic_tags = @xml = @order_id = '' @amount = @base_amount = @first_installment_amount = @initial_pre_auth_amount = @first_installment_interval = @recurring_amount = 0 @recurring_payment = @success = false @recurring_installment_interval_method = 'Daily' errors end |
Instance Attribute Details
#account_id ⇒ Object
Returns the value of attribute account_id.
43 44 45 |
# File 'lib/atpay/payment.rb', line 43 def account_id @account_id end |
#address ⇒ Object
Returns the value of attribute address.
17 18 19 |
# File 'lib/atpay/payment.rb', line 17 def address @address end |
#address2 ⇒ Object
Returns the value of attribute address2.
18 19 20 |
# File 'lib/atpay/payment.rb', line 18 def address2 @address2 end |
#amount ⇒ Object
charge info
31 32 33 |
# File 'lib/atpay/payment.rb', line 31 def amount @amount end |
#atpay_error ⇒ Object
internal
53 54 55 |
# File 'lib/atpay/payment.rb', line 53 def atpay_error @atpay_error end |
#base_amount ⇒ Object
Returns the value of attribute base_amount.
36 37 38 |
# File 'lib/atpay/payment.rb', line 36 def base_amount @base_amount end |
#city ⇒ Object
Returns the value of attribute city.
19 20 21 |
# File 'lib/atpay/payment.rb', line 19 def city @city end |
#credit_card_type ⇒ Object
Returns the value of attribute credit_card_type.
27 28 29 |
# File 'lib/atpay/payment.rb', line 27 def credit_card_type @credit_card_type end |
#cvv ⇒ Object
Returns the value of attribute cvv.
28 29 30 |
# File 'lib/atpay/payment.rb', line 28 def cvv @cvv end |
#dynamic_tags ⇒ Object
internal
53 54 55 |
# File 'lib/atpay/payment.rb', line 53 def @dynamic_tags end |
#email ⇒ Object
Returns the value of attribute email.
16 17 18 |
# File 'lib/atpay/payment.rb', line 16 def email @email end |
#error ⇒ Object
internal
53 54 55 |
# File 'lib/atpay/payment.rb', line 53 def error @error end |
#error_id ⇒ Object
internal
53 54 55 |
# File 'lib/atpay/payment.rb', line 53 def error_id @error_id end |
#errors ⇒ Object
internal
53 54 55 |
# File 'lib/atpay/payment.rb', line 53 def errors @errors end |
#expiration_date ⇒ Object
Returns the value of attribute expiration_date.
29 30 31 |
# File 'lib/atpay/payment.rb', line 29 def expiration_date @expiration_date end |
#first_installment_amount ⇒ Object
Returns the value of attribute first_installment_amount.
37 38 39 |
# File 'lib/atpay/payment.rb', line 37 def first_installment_amount @first_installment_amount end |
#first_installment_interval ⇒ Object
Returns the value of attribute first_installment_interval.
39 40 41 |
# File 'lib/atpay/payment.rb', line 39 def first_installment_interval @first_installment_interval end |
#first_name ⇒ Object
user info
14 15 16 |
# File 'lib/atpay/payment.rb', line 14 def first_name @first_name end |
#free_text ⇒ Object
Returns the value of attribute free_text.
33 34 35 |
# File 'lib/atpay/payment.rb', line 33 def free_text @free_text end |
#host ⇒ Object
Returns the value of attribute host.
11 12 13 |
# File 'lib/atpay/payment.rb', line 11 def host @host end |
#initial_pre_auth_amount ⇒ Object
Returns the value of attribute initial_pre_auth_amount.
38 39 40 |
# File 'lib/atpay/payment.rb', line 38 def initial_pre_auth_amount @initial_pre_auth_amount end |
#ip_address ⇒ Object
Returns the value of attribute ip_address.
23 24 25 |
# File 'lib/atpay/payment.rb', line 23 def ip_address @ip_address end |
#last_name ⇒ Object
Returns the value of attribute last_name.
15 16 17 |
# File 'lib/atpay/payment.rb', line 15 def last_name @last_name end |
#name_on_card ⇒ Object
card info
25 26 27 |
# File 'lib/atpay/payment.rb', line 25 def name_on_card @name_on_card end |
#number ⇒ Object
Returns the value of attribute number.
26 27 28 |
# File 'lib/atpay/payment.rb', line 26 def number @number end |
#order_id ⇒ Object
Returns the value of attribute order_id.
32 33 34 |
# File 'lib/atpay/payment.rb', line 32 def order_id @order_id end |
#org_options ⇒ Object
internal
53 54 55 |
# File 'lib/atpay/payment.rb', line 53 def @org_options end |
#password ⇒ Object
Returns the value of attribute password.
11 12 13 |
# File 'lib/atpay/payment.rb', line 11 def password @password end |
#phone ⇒ Object
Returns the value of attribute phone.
22 23 24 |
# File 'lib/atpay/payment.rb', line 22 def phone @phone end |
#recurring_amount ⇒ Object
Returns the value of attribute recurring_amount.
40 41 42 |
# File 'lib/atpay/payment.rb', line 40 def recurring_amount @recurring_amount end |
#recurring_installment_interval_method ⇒ Object
Returns the value of attribute recurring_installment_interval_method.
41 42 43 |
# File 'lib/atpay/payment.rb', line 41 def recurring_installment_interval_method @recurring_installment_interval_method end |
#recurring_installment_interval_method_additional_info ⇒ Object
Returns the value of attribute recurring_installment_interval_method_additional_info.
42 43 44 |
# File 'lib/atpay/payment.rb', line 42 def recurring_installment_interval_method_additional_info @recurring_installment_interval_method_additional_info end |
#recurring_payment ⇒ Object
recurrring info
35 36 37 |
# File 'lib/atpay/payment.rb', line 35 def recurring_payment @recurring_payment end |
#request ⇒ Object
results
48 49 50 |
# File 'lib/atpay/payment.rb', line 48 def request @request end |
#response ⇒ Object
Returns the value of attribute response.
49 50 51 |
# File 'lib/atpay/payment.rb', line 49 def response @response end |
#response_code ⇒ Object
internal
53 54 55 |
# File 'lib/atpay/payment.rb', line 53 def response_code @response_code end |
#service_expiry_method ⇒ Object
Returns the value of attribute service_expiry_method.
45 46 47 |
# File 'lib/atpay/payment.rb', line 45 def service_expiry_method @service_expiry_method end |
#service_expiry_method_additional_info ⇒ Object
Returns the value of attribute service_expiry_method_additional_info.
46 47 48 |
# File 'lib/atpay/payment.rb', line 46 def service_expiry_method_additional_info @service_expiry_method_additional_info end |
#state ⇒ Object
Returns the value of attribute state.
20 21 22 |
# File 'lib/atpay/payment.rb', line 20 def state @state end |
#sub_account_id ⇒ Object
Returns the value of attribute sub_account_id.
44 45 46 |
# File 'lib/atpay/payment.rb', line 44 def sub_account_id @sub_account_id end |
#success ⇒ Object
Returns the value of attribute success.
50 51 52 |
# File 'lib/atpay/payment.rb', line 50 def success @success end |
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
51 52 53 |
# File 'lib/atpay/payment.rb', line 51 def transaction_id @transaction_id end |
#username ⇒ Object
Returns the value of attribute username.
11 12 13 |
# File 'lib/atpay/payment.rb', line 11 def username @username end |
#xml ⇒ Object
internal
53 54 55 |
# File 'lib/atpay/payment.rb', line 53 def xml @xml end |
#zip ⇒ Object
Returns the value of attribute zip.
21 22 23 |
# File 'lib/atpay/payment.rb', line 21 def zip @zip end |
Instance Method Details
#charge(options = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/atpay/payment.rb', line 67 def charge( = {}) self.class.basic_auth(ATPAY.username, ATPAY.password) @org_options = #user info @first_name = [:first_name] if [:first_name] @last_name = [:last_name] if [:last_name] @email = [:email] if [:email] @address = [:address] if [:address] @address2 = [:address2] if [:address2] @city = [:city] if [:city] @state = [:state] if [:state] @zip = [:zip] if [:zip] @phone = [:phone] if [:phone] @ip_address = [:ip_address] if [:ip_address] #card info @name_on_card = [:name_on_card] @number = [:number] @cvv = [:cvv] @expiration_date = [:expiration_date] @credit_card_type = [:credit_card_type] if [:credit_card_type] #charge info @amount = [:amount] if [:amount] @order_id = [:order_id] if [:order_id] @free_text = [:free_text] if [:free_text] #recurring info @recurring_payment = [:recurring_payment] if [:recurring_payment] @base_amount = [:base_amount] if [:base_amount] @first_installment_amount = [:first_installment_amount] if [:first_installment_amount] @initial_pre_auth_amount = [:initial_pre_auth_amount] if [:initial_pre_auth_amount] @first_installment_interval = [:first_installment_interval] if [:first_installment_interval] @recurring_amount = [:recurring_amount] if [:recurring_amount] @recurring_installment_interval_method = [:recurring_installment_interval_method] if [:recurring_installment_interval_method] @recurring_installment_interval_additional_info = [:recurring_installment_interval_additional_info] if [:recurring_installment_interval_additional_info] @account_id = [:account_id] if [:account_id] @sub_account_id = [:sub_account_id] if [:sub_account_id] @service_expiry_method = [:service_expiry_method] if [:service_expiry_method] @service_expiry_method_additional_info = [:service_expiry_method_additional_info] if [:service_expiry_method_additional_info] @dynamic_tags = send_payment_request end |
#fire_payment_request ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/atpay/payment.rb', line 158 def fire_payment_request begin @request = @xml = render_xml puts @xml self.class.headers 'Content-Type' => 'text/xml; charset=utf-8', 'Content-Length' => @xml.length.to_s, 'SOAPAction' => soap_action @response = self.class.post(url, :body => @xml) puts @response.body rescue => e puts e end end |
#handle_payment_response ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/atpay/payment.rb', line 130 def handle_payment_response @success = false result = {} begin result = Crack::XML.parse(@response.body)['soap:Envelope']['soap:Body']['RegularTransactionResponse']['RegularTransactionResult'] @success = (result['SuccessFlag'] == 'true') rescue NoMethodError end if @success @transaction_id = result['TransactionID'] return true else if @response.body =~ /Unauthorized: Access is denied due to invalid credentials/ @error = 'Access is denied due to invalid credentials' else @error_id = @response.parsed_response["Envelope"]["Body"]["RegularTransactionResponse"]["RegularTransactionResult"]["ErrorID"] @error = "Sorry we were unable to process your card" @atpay_error = @errors[@error_id.to_i] if @errors[@error_id.to_i].present? end return false end end |
#render_xml ⇒ Object
172 173 174 175 176 |
# File 'lib/atpay/payment.rb', line 172 def render_xml @dynamic_tags = template = File.open(File.dirname(__FILE__)+'/request.xml.erb', 'r').read ERB.new(template).result(binding) end |
#send_payment_request ⇒ Object
124 125 126 127 128 |
# File 'lib/atpay/payment.rb', line 124 def send_payment_request fire_payment_request handle_payment_response success end |
#soap_action ⇒ Object
152 153 154 |
# File 'lib/atpay/payment.rb', line 152 def soap_action ['http://transactions.atpay.net','/webservices/ATPayTxWS/RegularTransaction'].join('') end |
#url ⇒ Object
155 156 157 |
# File 'lib/atpay/payment.rb', line 155 def url [@host,'/TxWS/ATPayTxWS.asmx'].join('') end |