Class: SolidusOpenPay::Gateway
- Inherits:
-
Object
- Object
- SolidusOpenPay::Gateway
- Defined in:
- app/models/solidus_open_pay/gateway.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #authorize(amount_in_cents, source, options = {}) ⇒ Object
- #capture(_amount_in_cents, authorization_id, options = {}) ⇒ Object
-
#initialize(options) ⇒ Gateway
constructor
A new instance of Gateway.
- #purchase(amount_in_cents, source, options = {}) ⇒ Object
- #void(authorization_id, _options = {}) ⇒ Object (also: #credit)
Constructor Details
#initialize(options) ⇒ Gateway
Returns a new instance of Gateway.
9 10 11 12 13 14 15 16 |
# File 'app/models/solidus_open_pay/gateway.rb', line 9 def initialize() @client = OpenpayApi.new( .fetch(:merchant_id, nil), .fetch(:private_key, nil), .fetch(:country, nil).presence || !.fetch(:test_mode, nil) ) @options = end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'app/models/solidus_open_pay/gateway.rb', line 7 def client @client end |
Instance Method Details
#authorize(amount_in_cents, source, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/solidus_open_pay/gateway.rb', line 18 def (amount_in_cents, source, = {}) resource_builder = ::SolidusOpenPay::Builders::Charge.new( source: source, amount: amount_in_cents, options: ) response = client.create(:charges).create( resource_builder.payload ) source&.update( authorization_id: response.try(:[], 'id') ) SolidusOpenPay::Response.build(response) rescue ::OpenpayTransactionException, ::OpenpayException, ::OpenpayConnectionException => e SolidusOpenPay::Response.build(e) end |
#capture(_amount_in_cents, authorization_id, options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/solidus_open_pay/gateway.rb', line 40 def capture(_amount_in_cents, , = {}) response = client.create(:charges).capture( ) json_response = JSON.parse(response.body) source = [:originator].try(:source) source&.update( capture_id: json_response.try(:[], 'id'), authorization_id: json_response.try(:[], 'authorization') ) SolidusOpenPay::Response.build(json_response) rescue ::OpenpayTransactionException, ::OpenpayException, ::OpenpayConnectionException => e SolidusOpenPay::Response.build(e) end |
#purchase(amount_in_cents, source, options = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/solidus_open_pay/gateway.rb', line 60 def purchase(amount_in_cents, source, = {}) resource_builder = ::SolidusOpenPay::Builders::Charge.new( source: source, amount: amount_in_cents, options: .merge({ capture: true }) ) response = client.create(:charges).create( resource_builder.payload ) source&.update( capture_id: response.try(:[], 'id'), authorization_id: response.try(:[], 'authorization') ) SolidusOpenPay::Response.build(response) rescue ::OpenpayTransactionException, ::OpenpayException, ::OpenpayConnectionException => e SolidusOpenPay::Response.build(e) end |
#void(authorization_id, _options = {}) ⇒ Object Also known as: credit
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/models/solidus_open_pay/gateway.rb', line 83 def void(, = {}) response = client.create(:charges).refund( , {} ) SolidusOpenPay::Response.build(response) rescue ::OpenpayTransactionException, ::OpenpayException, ::OpenpayConnectionException => e SolidusOpenPay::Response.build(e) end |