Class: Comgate::Gateway
- Inherits:
-
Object
- Object
- Comgate::Gateway
- Defined in:
- lib/comgate/gateway.rb
Constant Summary collapse
- BASE_URL =
"https://payments.comgate.cz/v1.0"
- DATA_CONVERSION_HASH =
{ curr: %i[payment currency], email: %i[payer email], label: %i[payment label], method: %i[payment method], price: %i[payment amount_in_cents], amount: %i[payment amount_in_cents], refId: %i[payment reference_id], account: %i[merchant target_shop_account], applePayPayload: %i[payment apple_pay_payload], country: %i[options country_code], dynamicExpiration: %i[payment dynamic_expiration], embedded: %i[options embedded_iframe], expirationTime: %i[payment expiration_time], lang: %i[options language_code], name: %i[payment product_name], phone: %i[payer phone], preauth: %i[payment preauthorization], verification: %i[payment verification_payment], ## not used for Comgate, but for other Gateway payments they are needed ## so here they are for evidence # firstName: %i[payer first_name], # lastName: %i[payer last_name], # street: %i[payer street_line], # city: %i[payer city], # postalCode: %i[payer postal_code], # payerCountryCode: %i[payer country_code], # description: %i[payment description], # returnUrl: %i[options shop_return_url], # callbackUrl: %i[options callback_url], # responses transId: %i[transaction_id], transferId: %i[transfer_id], code: %i[code], message: %i[message], extraMessage: %i[extra_message], payerId: %i[payer id], payerName: %i[payer account_name], payer_name: %i[payer account_name], payerAcc: %i[payer account_number], payer_acc: %i[payer account_number], fee: %i[payment fee], methods: %i[methods], vs: %i[payment variable_symbol], variableSymbol: %i[variable_symbol], transferDate: %i[transfer_date], accountCounterparty: %i[account_counterparty], accountOutgoing: %i[account_outgoing], status: %i[state], test: %i[test], merchant: %i[merchant gateway_id], secret: %i[secret], redirect: %i[redirect_to] }.freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #allowed_payment_methods(payment_data) ⇒ Object
- #cancel_preauthorized_transaction(transaction_id:) ⇒ Object
- #cancel_transaction(transaction_id:) ⇒ Object
- #check_transaction(transaction_id:) ⇒ Object (also: #check_state)
- #confirm_preauthorized_transaction(payment_data) ⇒ Object
- #download_zipped_csvs_of_transfers(date:, output_file_path:) ⇒ Object
-
#initialize(options) ⇒ Gateway
constructor
A new instance of Gateway.
- #process_callback(comgate_params) ⇒ Object (also: #process_payment_callback)
- #proxy_uri ⇒ Object
- #refund_transaction(payment_data) ⇒ Object
- #repeat_recurring_transaction(payment_data) ⇒ Object
- #start_preauthorized_transaction(payment_data) ⇒ Object
- #start_recurring_transaction(payment_data) ⇒ Object
- #start_transaction(payment_data) ⇒ Object
- #start_verification_transaction(payment_data) ⇒ Object
- #test_calls_used? ⇒ Boolean
- #transfers_from(date_or_time) ⇒ Object
Constructor Details
#initialize(options) ⇒ Gateway
Returns a new instance of Gateway.
67 68 69 70 71 72 |
# File 'lib/comgate/gateway.rb', line 67 def initialize() @options = return unless [:merchant_gateway_id].nil? || [:client_secret].nil? || [:test_calls].nil? raise ArgumentError, "options have to include :merchant_gateway_id, :client_secret and :test_calls" end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
65 66 67 |
# File 'lib/comgate/gateway.rb', line 65 def @options end |
Instance Method Details
#allowed_payment_methods(payment_data) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/comgate/gateway.rb', line 154 def allowed_payment_methods(payment_data) ph = gateway_params.merge(convert_data_to_comgate_params(%i[curr lang country], payment_data, required: false)) response = make_call(url: "#{BASE_URL}/methods", payload: ph, test_call: false, conversion_hash: { name: [:name] }) response.array = response.hash[:methods] response.hash = nil response end |
#cancel_preauthorized_transaction(transaction_id:) ⇒ Object
121 122 123 124 125 |
# File 'lib/comgate/gateway.rb', line 121 def (transaction_id:) make_call(url: "#{BASE_URL}/cancelPreauth", payload: gateway_params.merge(transId: transaction_id), test_call: false) end |
#cancel_transaction(transaction_id:) ⇒ Object
136 137 138 139 140 |
# File 'lib/comgate/gateway.rb', line 136 def cancel_transaction(transaction_id:) make_call(url: "#{BASE_URL}/cancel", payload: gateway_params.merge(transId: transaction_id), test_call: false) end |
#check_transaction(transaction_id:) ⇒ Object Also known as: check_state
142 143 144 145 146 |
# File 'lib/comgate/gateway.rb', line 142 def check_transaction(transaction_id:) make_call(url: "#{BASE_URL}/status", payload: gateway_params.merge(transId: transaction_id), test_call: false) end |
#confirm_preauthorized_transaction(payment_data) ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/comgate/gateway.rb', line 113 def (payment_data) params = convert_data_to_comgate_params(%i[transId amount], payment_data, required: true) make_call(url: "#{BASE_URL}/capturePreauth", payload: gateway_params.merge(params), test_call: false) end |
#download_zipped_csvs_of_transfers(date:, output_file_path:) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/comgate/gateway.rb', line 174 def download_zipped_csvs_of_transfers(date:, output_file_path:) date_str = date.strftime("%Y-%m-%d") resp = make_call(url: "#{BASE_URL}/csvDownload", payload: gateway_params.merge({ date: date_str }), test_call: false) tmp_file = resp.hash[:file] File.binwrite(output_file_path, tmp_file.read) tmp_file.close tmp_file.unlink resp.hash = { file_path: output_file_path } resp end |
#process_callback(comgate_params) ⇒ Object Also known as: process_payment_callback
149 150 151 |
# File 'lib/comgate/gateway.rb', line 149 def process_callback(comgate_params) Comgate::Response.new({ response_body: comgate_params }, DATA_CONVERSION_HASH) end |
#proxy_uri ⇒ Object
78 79 80 |
# File 'lib/comgate/gateway.rb', line 78 def proxy_uri [:proxy_uri] end |
#refund_transaction(payment_data) ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/comgate/gateway.rb', line 127 def refund_transaction(payment_data) refund_params = convert_data_to_comgate_params(%i[transId amount], payment_data, required: true) refund_params.merge!(convert_data_to_comgate_params(%i[curr refId], payment_data, required: false)) make_call(url: "#{BASE_URL}/refund", payload: gateway_params.merge(refund_params), test_call: test_call?(payment_data[:test])) end |
#repeat_recurring_transaction(payment_data) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/comgate/gateway.rb', line 94 def repeat_recurring_transaction(payment_data) init_transaction_id = payment_data[:payment][:recurrence].delete(:init_transaction_id) make_call(url: "#{BASE_URL}/recurring", payload: single_payment_payload(payment_data).merge(initRecurringId: init_transaction_id), test_call: test_call?(payment_data[:test])) end |
#start_preauthorized_transaction(payment_data) ⇒ Object
107 108 109 110 111 |
# File 'lib/comgate/gateway.rb', line 107 def (payment_data) make_call(url: "#{BASE_URL}/create", payload: single_payment_payload(payment_data).merge(preauth: true), test_call: test_call?(payment_data[:test])) end |
#start_recurring_transaction(payment_data) ⇒ Object
88 89 90 91 92 |
# File 'lib/comgate/gateway.rb', line 88 def start_recurring_transaction(payment_data) make_call(url: "#{BASE_URL}/create", payload: single_payment_payload(payment_data).merge(initRecurring: true), test_call: test_call?(payment_data[:test])) end |
#start_transaction(payment_data) ⇒ Object
82 83 84 85 86 |
# File 'lib/comgate/gateway.rb', line 82 def start_transaction(payment_data) make_call(url: "#{BASE_URL}/create", payload: single_payment_payload(payment_data), test_call: test_call?(payment_data[:test])) end |
#start_verification_transaction(payment_data) ⇒ Object
101 102 103 104 105 |
# File 'lib/comgate/gateway.rb', line 101 def start_verification_transaction(payment_data) make_call(url: "#{BASE_URL}/create", payload: single_payment_payload(payment_data).merge(verification: true), test_call: test_call?(payment_data[:test])) end |
#test_calls_used? ⇒ Boolean
74 75 76 |
# File 'lib/comgate/gateway.rb', line 74 def test_calls_used? [:test_calls] == true end |
#transfers_from(date_or_time) ⇒ Object
166 167 168 169 170 171 172 |
# File 'lib/comgate/gateway.rb', line 166 def transfers_from(date_or_time) date_str = date_or_time.strftime("%Y-%m-%d") make_call(url: "#{BASE_URL}/transferList", payload: gateway_params.merge({ date: date_str }), test_call: false) end |