Class: PaymentsApi::PaymentsController
- Inherits:
-
BaseController
- Object
- BaseController
- PaymentsApi::PaymentsController
- Defined in:
- lib/payments_api/controllers/payments_controller.rb
Overview
PaymentsController
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
-
#approve_payment(bank_id, payment_id) ⇒ void
Approves a Payment to be sent.
-
#cancel_payment(bank_id, payment_id) ⇒ void
Attempts to cancel a Payment.
-
#create_payment(bank_id, body) ⇒ Payment
Creates a new Payment.
-
#initialize(config, http_call_back: nil) ⇒ PaymentsController
constructor
A new instance of PaymentsController.
-
#update_payment(bank_id, payment_id, body) ⇒ Payment
Update the data for a Payment before it is approved or sent.
-
#validate_iban(bank_id, iban) ⇒ BankAccount
Validates an IBAN and returns the bank account information client, sell foreign currency in exchange for local currency.
Methods inherited from BaseController
#execute_request, #validate_parameters, #validate_response
Constructor Details
#initialize(config, http_call_back: nil) ⇒ PaymentsController
Returns a new instance of PaymentsController.
9 10 11 |
# File 'lib/payments_api/controllers/payments_controller.rb', line 9 def initialize(config, http_call_back: nil) super(config, http_call_back: http_call_back) end |
Instance Method Details
#approve_payment(bank_id, payment_id) ⇒ void
This method returns an undefined value.
Approves a Payment to be sent
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/payments_api/controllers/payments_controller.rb', line 174 def approve_payment(bank_id, payment_id) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/payments/{paymentId}/approve' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'paymentId' => { 'value' => payment_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'bankId' => bank_id } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers ) CustomHeaderAuth.apply(config, _request) _response = execute_request(_request) # Validate response against endpoint and global error codes. if _response.status_code == 400 raise RequestErrorException.new( 'Error in Request', _response ) elsif _response.status_code == 403 raise APIException.new( 'Forbidden', _response ) elsif _response.status_code == 500 raise RequestErrorException.new( 'System Error', _response ) end validate_response(_response) end |
#cancel_payment(bank_id, payment_id) ⇒ void
This method returns an undefined value.
Attempts to cancel a Payment. Does not automatically cancel the linked Quote.
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 111 |
# File 'lib/payments_api/controllers/payments_controller.rb', line 69 def cancel_payment(bank_id, payment_id) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/payments/{paymentId}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'paymentId' => { 'value' => payment_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'bankId' => bank_id } # Prepare and execute HttpRequest. _request = config.http_client.delete( _query_url, headers: _headers ) CustomHeaderAuth.apply(config, _request) _response = execute_request(_request) # Validate response against endpoint and global error codes. if _response.status_code == 400 raise RequestErrorException.new( 'Error in Request', _response ) elsif _response.status_code == 403 raise APIException.new( 'Forbidden', _response ) elsif _response.status_code == 500 raise RequestErrorException.new( 'System Error', _response ) end validate_response(_response) end |
#create_payment(bank_id, body) ⇒ Payment
Creates a new Payment
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/payments_api/controllers/payments_controller.rb', line 17 def create_payment(bank_id, body) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/payments' _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8', 'bankId' => bank_id } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) CustomHeaderAuth.apply(config, _request) _response = execute_request(_request) # Validate response against endpoint and global error codes. if _response.status_code == 400 raise RequestErrorException.new( 'Error in Request', _response ) elsif _response.status_code == 403 raise APIException.new( 'Forbidden', _response ) elsif _response.status_code == 500 raise RequestErrorException.new( 'System Error', _response ) end validate_response(_response) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) Payment.from_hash(decoded) end |
#update_payment(bank_id, payment_id, body) ⇒ Payment
Update the data for a Payment before it is approved or sent
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/payments_api/controllers/payments_controller.rb', line 118 def update_payment(bank_id, payment_id, body) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/payments/{paymentId}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'paymentId' => { 'value' => payment_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8', 'bankId' => bank_id } # Prepare and execute HttpRequest. _request = config.http_client.put( _query_url, headers: _headers, parameters: body.to_json ) CustomHeaderAuth.apply(config, _request) _response = execute_request(_request) # Validate response against endpoint and global error codes. if _response.status_code == 400 raise RequestErrorException.new( 'Error in Request', _response ) elsif _response.status_code == 403 raise APIException.new( 'Forbidden', _response ) elsif _response.status_code == 500 raise RequestErrorException.new( 'System Error', _response ) end validate_response(_response) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) Payment.from_hash(decoded) end |
#validate_iban(bank_id, iban) ⇒ BankAccount
Validates an IBAN and returns the bank account information client, sell foreign currency in exchange for local currency
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/payments_api/controllers/payments_controller.rb', line 223 def validate_iban(bank_id, iban) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/payments/get-bank-account-from-iban' _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, 'iban' => iban ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'bankId' => bank_id } # Prepare and execute HttpRequest. _request = config.http_client.get( _query_url, headers: _headers ) CustomHeaderAuth.apply(config, _request) _response = execute_request(_request) # Validate response against endpoint and global error codes. if _response.status_code == 400 raise RequestErrorException.new( 'Error in Request', _response ) elsif _response.status_code == 403 raise APIException.new( 'Forbidden', _response ) elsif _response.status_code == 500 raise RequestErrorException.new( 'System Error', _response ) end validate_response(_response) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) BankAccount.from_hash(decoded) end |