Class: Gateway::PaywayV2
- Inherits:
-
PaymentMethod
- Object
- PaymentMethod
- Gateway::PaywayV2
- Defined in:
- app/models/spree/gateway/payway_v2.rb
Instance Method Summary collapse
-
#authorize(_amount, _source, gateway_options = {}) ⇒ Object
override authorize is used when pre auth enabled.
-
#auto_capture? ⇒ Boolean
override authorize payment if pre-auth is enabled, otherwise purchase / complete immediately.
-
#cancel(_response_code, _payment) ⇒ Object
override.
-
#capture(_amount, _response_code, gateway_options) ⇒ Object
override.
-
#default_payout_profile ⇒ Object
override.
-
#enable_payout? ⇒ Boolean
override.
-
#enable_pre_auth? ⇒ Boolean
override.
-
#method_type ⇒ Object
override: partial to render in admin.
-
#payment_source_class ⇒ Object
override.
-
#purchase(_amount, _source, gateway_options = {}) ⇒ Object
override purchase is used when pre auth disabled.
-
#support_payout? ⇒ Boolean
override.
-
#support_pre_auth? ⇒ Boolean
override.
-
#void(_response_code, gateway_options) ⇒ Object
override.
Instance Method Details
#authorize(_amount, _source, gateway_options = {}) ⇒ Object
override authorize is used when pre auth enabled
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/spree/gateway/payway_v2.rb', line 54 def (_amount, _source, = {}) _, payment_number = [:order_id].split('-') payment = Spree::Payment.find_by(number: payment_number) checker = check_transaction(payment) payment.update(transaction_response: checker.json_response) if checker.success? ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Authorized') else ActiveMerchant::Billing::Response.new(false, 'Payway Gateway: Authorization Failed') end end |
#auto_capture? ⇒ Boolean
override authorize payment if pre-auth is enabled, otherwise purchase / complete immediately.
48 49 50 |
# File 'app/models/spree/gateway/payway_v2.rb', line 48 def auto_capture? !enable_pre_auth? end |
#cancel(_response_code, _payment) ⇒ Object
override
127 128 129 |
# File 'app/models/spree/gateway/payway_v2.rb', line 127 def cancel(_response_code, _payment) ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Payment has been canceled.') end |
#capture(_amount, _response_code, gateway_options) ⇒ Object
override
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/models/spree/gateway/payway_v2.rb', line 90 def capture(_amount, _response_code, ) _, payment_number = [:order_id].split('-') payment = Spree::Payment.find_by(number: payment_number) success = true params = {} success, params[:pre_auth] = complete_pre_auth(payment) if enable_pre_auth? success, params[:payout] = confirm_payouts(payment) if success && payout_total_from_response(payment).present? if success ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Captured', params) else ActiveMerchant::Billing::Response.new(false, 'Payway Gateway: Capture Failed', params) end end |
#default_payout_profile ⇒ Object
override
19 20 21 |
# File 'app/models/spree/gateway/payway_v2.rb', line 19 def default_payout_profile Spree::PayoutProfiles::PaywayV2.default end |
#enable_payout? ⇒ Boolean
override
37 38 39 |
# File 'app/models/spree/gateway/payway_v2.rb', line 37 def enable_payout? default_payout_profile.present? && default_payout_profile.receivable? end |
#enable_pre_auth? ⇒ Boolean
override
42 43 44 |
# File 'app/models/spree/gateway/payway_v2.rb', line 42 def enable_pre_auth? self[:enable_pre_auth] end |
#method_type ⇒ Object
override: partial to render in admin
14 15 16 |
# File 'app/models/spree/gateway/payway_v2.rb', line 14 def method_type 'payway_v2' end |
#payment_source_class ⇒ Object
override
24 25 26 |
# File 'app/models/spree/gateway/payway_v2.rb', line 24 def payment_source_class Spree::VpagoPaymentSource end |
#purchase(_amount, _source, gateway_options = {}) ⇒ Object
override purchase is used when pre auth disabled
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/models/spree/gateway/payway_v2.rb', line 70 def purchase(_amount, _source, = {}) _, payment_number = [:order_id].split('-') payment = Spree::Payment.find_by(number: payment_number) checker = check_transaction(payment) payment.update(transaction_response: checker.json_response) success = checker.success? params = {} success, params[:payout] = confirm_payouts(payment) if success && payout_total_from_response(payment).present? if success ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Purchased', params) else ActiveMerchant::Billing::Response.new(false, 'Payway Gateway: Purchasing Failed', params) end end |
#support_payout? ⇒ Boolean
override
29 30 31 |
# File 'app/models/spree/gateway/payway_v2.rb', line 29 def support_payout? preferred_payment_option.in?(%w[abapay_khqr abapay_khqr_deeplink]) end |
#support_pre_auth? ⇒ Boolean
override
34 |
# File 'app/models/spree/gateway/payway_v2.rb', line 34 def support_pre_auth? = true |
#void(_response_code, gateway_options) ⇒ Object
override
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/models/spree/gateway/payway_v2.rb', line 108 def void(_response_code, ) _, payment_number = [:order_id].split('-') payment = Spree::Payment.find_by(number: payment_number) if enable_pre_auth? params = {} success, params[:pre_auth] = cancel_pre_auth(payment) if success ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Pre-authorization successfully canceled.', params) else ActiveMerchant::Billing::Response.new(false, 'Payway Gateway: Failed to cancel pre-authorization.', params) end else ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Payment has been voided.') end end |