Class: Buckaruby::Gateway
- Inherits:
-
Object
- Object
- Buckaruby::Gateway
- Extended by:
- Forwardable
- Defined in:
- lib/buckaruby/gateway.rb
Overview
Implementation of the BPE 3.0 NVP Gateway.
Instance Method Summary collapse
-
#cancel_transaction(options = {}) ⇒ Object
Cancel a transaction.
-
#cancellable_transaction?(options = {}) ⇒ Boolean
Checks if a transaction is cancellable.
-
#initialize(options = {}) ⇒ Gateway
constructor
A new instance of Gateway.
-
#issuers(payment_method) ⇒ Object
Get a list with payment issuers (currently only iDEAL).
-
#parse_push(response) ⇒ Object
Parse and verify the push response.
-
#payment_methods ⇒ Object
Returns the payment methods enabled by Buckaroo and supported by this library.
-
#recurrent_transaction(options = {}) ⇒ Object
Setup a recurrent transaction.
-
#refund_transaction(options = {}) ⇒ Object
Refund a transaction.
-
#refundable_transaction?(options = {}) ⇒ Boolean
Checks if a transaction is refundable.
-
#setup_transaction(options = {}) ⇒ Object
Setup a new transaction.
-
#specify_transaction(options = {}) ⇒ Object
Retrieve the specification for setting up a transaction.
-
#status(options = {}) ⇒ Object
Get transaction status.
Constructor Details
#initialize(options = {}) ⇒ Gateway
Returns a new instance of Gateway.
12 13 14 |
# File 'lib/buckaruby/gateway.rb', line 12 def initialize( = {}) @options = end |
Instance Method Details
#cancel_transaction(options = {}) ⇒ Object
Cancel a transaction.
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/buckaruby/gateway.rb', line 123 def cancel_transaction( = {}) logger.debug("[cancel_transaction] options=#{.inspect}") validate_required_params!(, :transaction_id) response = execute_request(:status, ) unless response.cancellable? raise NonCancellableTransactionException, [:transaction_id] end execute_request(:cancel, ) end |
#cancellable_transaction?(options = {}) ⇒ Boolean
Checks if a transaction is cancellable.
113 114 115 116 117 118 119 120 |
# File 'lib/buckaruby/gateway.rb', line 113 def cancellable_transaction?( = {}) logger.debug("[cancellable_transaction?] options=#{.inspect}") validate_required_params!(, :transaction_id) response = execute_request(:status, ) response.cancellable? end |
#issuers(payment_method) ⇒ Object
Get a list with payment issuers (currently only iDEAL).
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/buckaruby/gateway.rb', line 27 def issuers(payment_method) if payment_method != PaymentMethod::IDEAL && payment_method != PaymentMethod::IDEAL_PROCESSING raise ArgumentError, 'Invalid payment method, only iDEAL is supported.' end response = execute_request(:specify_transaction, payment_method: payment_method) service = response.services.first description = service[:actiondescription].find { |action| action[:description].casecmp(Action::PAY).zero? } if service params = description[:requestparameters].find { |param| param[:name].casecmp('issuer').zero? } if description items = params[:listitemdescription] if params items.to_h { |item| [item[:value], item[:description]] } end |
#parse_push(response) ⇒ Object
Parse and verify the push response.
137 138 139 140 141 142 143 |
# File 'lib/buckaruby/gateway.rb', line 137 def parse_push(response) if response.nil? || response.empty? raise ArgumentError, 'No push parameters found' end PushResponse.new(response, config) end |
#payment_methods ⇒ Object
Returns the payment methods enabled by Buckaroo and supported by this library.
17 18 19 20 21 22 23 24 |
# File 'lib/buckaruby/gateway.rb', line 17 def payment_methods valid_payment_methods = PaymentMethod.all - [PaymentMethod::TRANSFER] response = execute_request(:specify_transaction) services = response.services.map { |service| service[:name] } services & valid_payment_methods end |
#recurrent_transaction(options = {}) ⇒ Object
Setup a recurrent transaction.
54 55 56 57 58 59 60 |
# File 'lib/buckaruby/gateway.rb', line 54 def recurrent_transaction( = {}) logger.debug("[recurrent_transaction] options=#{.inspect}") validate_recurrent_transaction_params!() execute_request(:recurrent_transaction, ) end |
#refund_transaction(options = {}) ⇒ Object
Refund a transaction.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/buckaruby/gateway.rb', line 80 def refund_transaction( = {}) logger.debug("[refund_transaction] options=#{.inspect}") validate_refund_transaction_params!() response = execute_request(:refund_info, ) unless response.refundable? raise NonRefundableTransactionException, [:transaction_id] end # Pick maximum refundable amount if amount is not supplied. [:amount] = response.maximum_amount unless [:amount] # Fill required parameters with data from refund info request. .merge!( payment_method: response.payment_method, invoicenumber: response.invoicenumber, currency: response.currency ) execute_request(:refund_transaction, ) end |
#refundable_transaction?(options = {}) ⇒ Boolean
Checks if a transaction is refundable.
70 71 72 73 74 75 76 77 |
# File 'lib/buckaruby/gateway.rb', line 70 def refundable_transaction?( = {}) logger.debug("[refundable_transaction?] options=#{.inspect}") validate_required_params!(, :transaction_id) response = execute_request(:refund_info, ) response.refundable? end |
#setup_transaction(options = {}) ⇒ Object
Setup a new transaction.
43 44 45 46 47 48 49 50 51 |
# File 'lib/buckaruby/gateway.rb', line 43 def setup_transaction( = {}) logger.debug("[setup_transaction] options=#{.inspect}") validate_setup_transaction_params!() normalize_consumer_iban!() if [:payment_method] == PaymentMethod::SEPA_DIRECT_DEBIT execute_request(:setup_transaction, ) end |
#specify_transaction(options = {}) ⇒ Object
Retrieve the specification for setting up a transaction.
63 64 65 66 67 |
# File 'lib/buckaruby/gateway.rb', line 63 def specify_transaction( = {}) logger.debug("[specify_transaction] options=#{.inspect}") execute_request(:specify_transaction, ) end |
#status(options = {}) ⇒ Object
Get transaction status.
104 105 106 107 108 109 110 |
# File 'lib/buckaruby/gateway.rb', line 104 def status( = {}) logger.debug("[status] options=#{.inspect}") validate_status_params!() execute_request(:status, ) end |