Class: GoPay::BasePayment
- Inherits:
-
Object
- Object
- GoPay::BasePayment
- Defined in:
- lib/gopay/models/base_payment.rb
Instance Attribute Summary collapse
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#country_code ⇒ Object
readonly
Returns the value of attribute country_code.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#default_payment_channel ⇒ Object
readonly
Returns the value of attribute default_payment_channel.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#lang ⇒ Object
readonly
Returns the value of attribute lang.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#order_number ⇒ Object
readonly
Returns the value of attribute order_number.
-
#p1 ⇒ Object
readonly
Returns the value of attribute p1.
-
#p2 ⇒ Object
readonly
Returns the value of attribute p2.
-
#p3 ⇒ Object
readonly
Returns the value of attribute p3.
-
#p4 ⇒ Object
readonly
Returns the value of attribute p4.
-
#payment_channels ⇒ Object
readonly
Returns the value of attribute payment_channels.
-
#payment_session_id ⇒ Object
Returns the value of attribute payment_session_id.
-
#phone_number ⇒ Object
readonly
Returns the value of attribute phone_number.
-
#postal_code ⇒ Object
readonly
Returns the value of attribute postal_code.
-
#product_name ⇒ Object
readonly
Returns the value of attribute product_name.
-
#response ⇒ Object
Returns the value of attribute response.
-
#secure_key ⇒ Object
readonly
Returns the value of attribute secure_key.
-
#session_state ⇒ Object
readonly
Returns the value of attribute session_state.
-
#street ⇒ Object
readonly
Returns the value of attribute street.
-
#target_goid ⇒ Object
readonly
Returns the value of attribute target_goid.
-
#total_price_in_cents ⇒ Object
readonly
Returns the value of attribute total_price_in_cents.
Instance Method Summary collapse
- #concat_payment_command ⇒ Object
- #concat_payment_identity(params) ⇒ Object
- #concat_payment_session ⇒ Object
- #concat_payment_status(response) ⇒ Object
- #create ⇒ Object
- #gopay_url ⇒ Object
-
#initialize(attributes = {}) ⇒ BasePayment
constructor
A new instance of BasePayment.
- #is_in_status?(status) ⇒ Boolean
- #load(validated_status = nil) ⇒ Object
- #payment_command_hash ⇒ Object
- #payment_session_hash ⇒ Object
- #valid_identity?(params, padding_off = false) ⇒ Boolean
- #valid_payment_session?(response, status = nil) ⇒ Boolean
- #valid_response?(response, status) ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ BasePayment
Returns a new instance of BasePayment.
7 8 9 10 11 12 13 14 15 |
# File 'lib/gopay/models/base_payment.rb', line 7 def initialize(attributes = {}) attributes.each do |key, value| instance_variable_set(:"@#{key}", value) if self.respond_to?(key) end @target_goid ||= GoPay.configuration.goid.to_s @secure_key ||= GoPay.configuration.secure_key.to_s @payment_channels ||= [] @payment_channels = @payment_channels.join(',') end |
Instance Attribute Details
#city ⇒ Object (readonly)
Returns the value of attribute city.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def city @city end |
#country_code ⇒ Object (readonly)
Returns the value of attribute country_code.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def country_code @country_code end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def currency @currency end |
#default_payment_channel ⇒ Object (readonly)
Returns the value of attribute default_payment_channel.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def default_payment_channel @default_payment_channel end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def email @email end |
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def first_name @first_name end |
#lang ⇒ Object (readonly)
Returns the value of attribute lang.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def lang @lang end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def last_name @last_name end |
#order_number ⇒ Object (readonly)
Returns the value of attribute order_number.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def order_number @order_number end |
#p1 ⇒ Object (readonly)
Returns the value of attribute p1.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def p1 @p1 end |
#p2 ⇒ Object (readonly)
Returns the value of attribute p2.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def p2 @p2 end |
#p3 ⇒ Object (readonly)
Returns the value of attribute p3.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def p3 @p3 end |
#p4 ⇒ Object (readonly)
Returns the value of attribute p4.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def p4 @p4 end |
#payment_channels ⇒ Object (readonly)
Returns the value of attribute payment_channels.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def payment_channels @payment_channels end |
#payment_session_id ⇒ Object
Returns the value of attribute payment_session_id.
23 24 25 |
# File 'lib/gopay/models/base_payment.rb', line 23 def payment_session_id @payment_session_id end |
#phone_number ⇒ Object (readonly)
Returns the value of attribute phone_number.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def phone_number @phone_number end |
#postal_code ⇒ Object (readonly)
Returns the value of attribute postal_code.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def postal_code @postal_code end |
#product_name ⇒ Object (readonly)
Returns the value of attribute product_name.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def product_name @product_name end |
#response ⇒ Object
Returns the value of attribute response.
23 24 25 |
# File 'lib/gopay/models/base_payment.rb', line 23 def response @response end |
#secure_key ⇒ Object (readonly)
Returns the value of attribute secure_key.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def secure_key @secure_key end |
#session_state ⇒ Object (readonly)
Returns the value of attribute session_state.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def session_state @session_state end |
#street ⇒ Object (readonly)
Returns the value of attribute street.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def street @street end |
#target_goid ⇒ Object (readonly)
Returns the value of attribute target_goid.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def target_goid @target_goid end |
#total_price_in_cents ⇒ Object (readonly)
Returns the value of attribute total_price_in_cents.
17 18 19 |
# File 'lib/gopay/models/base_payment.rb', line 17 def total_price_in_cents @total_price_in_cents end |
Instance Method Details
#concat_payment_command ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/gopay/models/base_payment.rb', line 126 def concat_payment_command [target_goid, product_name.strip, total_price_in_cents, currency, order_number, GoPay.configuration.failed_url, GoPay.configuration.success_url, 0, #preAuthorization 0, #recurrentPayment nil, #recurrenceDateTo nil, #recurrenceCycle nil, #recurrencePeriod, payment_channels, secure_key].map { |attr| attr.to_s }.join("|") end |
#concat_payment_identity(params) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/gopay/models/base_payment.rb', line 118 def concat_payment_identity(params) [params['targetGoId'], params['paymentSessionId'], params['parentPaymentSessionId'], params['orderNumber'], secure_key].map { |attr| attr.to_s.strip }.join("|") end |
#concat_payment_session ⇒ Object
143 144 145 146 147 |
# File 'lib/gopay/models/base_payment.rb', line 143 def concat_payment_session [target_goid, payment_session_id, secure_key].map { |attr| attr.to_s.strip }.join("|") end |
#concat_payment_status(response) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/gopay/models/base_payment.rb', line 149 def concat_payment_status(response) [response[:target_go_id], response[:product_name], response[:total_price], response[:currency], response[:order_number], response[:recurrent_payment] ? 1 : 0, response[:parent_payment_session_id], response[:pre_authorization] ? 1 : 0, response[:result], response[:session_state], response[:session_sub_state], response[:payment_channel], secure_key].map { |attr| attr.is_a?(Hash) ? "" : attr.to_s }.join("|") end |
#create ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gopay/models/base_payment.rb', line 25 def create client = Savon::Client.new :wsdl => GoPay.configuration.urls["wsdl"], :log => false soap_response = client.call :create_payment, :message => { :payment_command => payment_command_hash } self.response = soap_response.to_hash[:create_payment_response][:create_payment_return] valid_response?(response, GoPay::STATUSES[:created]) valid = valid_response?(response, GoPay::STATUSES[:created]) self.payment_session_id = response[:payment_session_id] if valid valid end |
#gopay_url ⇒ Object
165 166 167 168 169 170 171 172 |
# File 'lib/gopay/models/base_payment.rb', line 165 def gopay_url return unless payment_session_id parameters = {"sessionInfo.targetGoId" => target_goid, "sessionInfo.paymentSessionId" => payment_session_id, "sessionInfo.encryptedSignature" => GoPay::Crypt.encrypt(self.concat_payment_session)} query_string = parameters.map { |key, value| "#{key}=#{value}" }.join("&") GoPay.configuration.urls["full_integration"] + "?" + query_string end |
#is_in_status?(status) ⇒ Boolean
44 45 46 |
# File 'lib/gopay/models/base_payment.rb', line 44 def is_in_status?(status) load(status) end |
#load(validated_status = nil) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/gopay/models/base_payment.rb', line 36 def load(validated_status = nil) client = Savon::Client.new :wsdl => GoPay.configuration.urls["wsdl"], :log => false soap_response = client.call :payment_status, :message => { :payment_session_info => payment_session_hash } self.response = soap_response.to_hash[:payment_status_response][:payment_status_return] valid_payment_session?(response, validated_status) end |
#payment_command_hash ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/gopay/models/base_payment.rb', line 48 def payment_command_hash {"targetGoId" => target_goid.to_i, "productName" => product_name, "totalPrice" => total_price_in_cents, "currency" => currency, "orderNumber" => order_number, "successURL" => GoPay.configuration.success_url, "failedURL" => GoPay.configuration.failed_url, "preAuthorization" => false, "defaultPaymentChannel" => default_payment_channel, "recurrentPayment" => false, "encryptedSignature" => GoPay::Crypt.encrypt(concat_payment_command), "customerData" => { "firstName" => first_name, "lastName" => last_name, "city" => city, "street" => street, "postalCode" => postal_code, "countryCode" => country_code, "email" => email, "phoneNumber" => phone_number}, "paymentChannels" => payment_channels, "lang" => lang} end |
#payment_session_hash ⇒ Object
73 74 75 76 77 |
# File 'lib/gopay/models/base_payment.rb', line 73 def payment_session_hash {"targetGoId" => target_goid.to_i, "paymentSessionId" => payment_session_id, "encryptedSignature" => GoPay::Crypt.encrypt(concat_payment_session)} end |
#valid_identity?(params, padding_off = false) ⇒ Boolean
111 112 113 114 115 116 |
# File 'lib/gopay/models/base_payment.rb', line 111 def valid_identity?(params, padding_off = false) raise 'invalid targetGoId' unless params['targetGoId'] == target_goid.to_s raise 'invalid orderNumber' unless params['orderNumber'] == order_number.to_s raise 'invalid encryptedSignature' unless GoPay::Crypt.sha1(concat_payment_identity(params)) == GoPay::Crypt.decrypt(params['encryptedSignature'], padding_off) true end |
#valid_payment_session?(response, status = nil) ⇒ Boolean
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/gopay/models/base_payment.rb', line 91 def valid_payment_session?(response, status = nil) raise "CALL NOT COMPLETED " if response[:result] != GoPay::STATUSES[:call_completed] status_valid = if status response[:session_state] == status else GoPay::STATUSES.values.include?(response[:session_state]) end response_valid = {:order_number => order_number, :product_name => product_name, :target_go_id => target_goid, :total_price => total_price_in_cents, :currency => currency }.all? { |key, value| response[key].to_s == value.to_s } signature_valid = GoPay::Crypt.sha1(concat_payment_status(response)) == GoPay::Crypt.decrypt(response[:encrypted_signature]) status_valid && response_valid && signature_valid end |
#valid_response?(response, status) ⇒ Boolean
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/gopay/models/base_payment.rb', line 79 def valid_response?(response, status) raise "CALL NOT COMPLETED " if response[:result] != GoPay::STATUSES[:call_completed] goid_valid = (response[:target_go_id].to_s == target_goid) response_valid = {:session_state => status, :product_name => product_name, :total_price => total_price_in_cents.to_s }.all? { |key, value| response[key].to_s == value.to_s } response_valid && goid_valid end |