Class: PaymentMethod::Komerci
- Inherits:
-
PaymentMethod
- Object
- PaymentMethod
- PaymentMethod::Komerci
- Defined in:
- app/models/spree/payment_method/komerci.rb
Instance Method Summary collapse
-
#authorize(_amount, source, gateway_options) ⇒ ActiveMerchant::Billing::Response
Authorizes the payment to Cielo.
-
#cancel(response_code) ⇒ ActiveMerchant::Billing::Response
Cancel the payment.
-
#capture(amount, response_code, _gateway_options) ⇒ ActiveMerchant::Billing::Response
Captures the payment.
- #payment_source_class ⇒ Object
-
#purchase(_amount, source, gateway_options) ⇒ ActiveMerchant::Billing::Response
Purchases the payment to Komerci.
-
#void(response_code, _gateway_options) ⇒ ActiveMerchant::Billing::Response
Voids the payment.
Instance Method Details
#authorize(_amount, source, gateway_options) ⇒ ActiveMerchant::Billing::Response
Authorizes the payment to Cielo
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/spree/payment_method/komerci.rb', line 42 def (_amount, source, ) if [:portions].nil? return ActiveMerchant::Billing::Response.new(false, Spree.t('komerci.messages.invalid_portions'), {}, {}) end params = source, params[:transacao] = '73' if [:portions] == 1 params[:parcelas] = '00' else params[:parcelas] = [:portions] end response = Spree::KomerciConfig. params (source, , response, 'authorize') end |
#cancel(response_code) ⇒ ActiveMerchant::Billing::Response
Cancel the payment
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'app/models/spree/payment_method/komerci.rb', line 140 def cancel(response_code) transaction = Spree::KomerciTransaction.find_by order_number: response_code params = { total: transaction.total, filiacao: Spree::KomerciConfig[:afiliation_key], numcv: transaction.order_number, numautor: transaction., usr: Spree::KomerciConfig[:komerci_user], pwd: Spree::KomerciConfig[:komerci_password], concentrador: nil } response = Spree::KomerciConfig.void_transaction params if response[:success] == true ActiveMerchant::Billing::Response.new(true, Spree.t('komerci.messages.cancel_success'), {}, authorization: response_code) else # Retorna como cancelado, mas avisando que o cancelamento deve ser feito no Portal ActiveMerchant::Billing::Response.new(true, Spree.t('komerci.messages.cancel_error_date'), {}, authorization: response_code) end end |
#capture(amount, response_code, _gateway_options) ⇒ ActiveMerchant::Billing::Response
Captures the payment
67 68 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 |
# File 'app/models/spree/payment_method/komerci.rb', line 67 def capture(amount, response_code, ) total = sprintf('%0.2f', amount / 100) transaction = Spree::KomerciTransaction.find_by order_number: response_code if transaction.payment.portions == 1 transaction_option = '04' portions = '00' else transaction_option = Spree::KomerciConfig[:portions_type] portions = transaction.payment.portions end params = { filiacao: Spree::KomerciConfig[:afiliation_key], total: total, transorig: transaction_option, parcelas: portions, data: transaction.created_at.strftime('%Y%m%d'), numautor: transaction., numcv: transaction.order_number, usr: Spree::KomerciConfig[:komerci_user], pwd: Spree::KomerciConfig[:komerci_password], distribuidor: nil, concentrador: nil } response = Spree::KomerciConfig. params if response[:success] == true ActiveMerchant::Billing::Response.new(true, Spree.t('komerci.messages.capture_success'), {}, authorization: response_code) else = response[:data][:error_number] ? "#{response[:data][:error_number]}: " : '' << response[:data][:error_message] ActiveMerchant::Billing::Response.new(false, , {}, authorization: response_code) end end |
#payment_source_class ⇒ Object
4 5 6 |
# File 'app/models/spree/payment_method/komerci.rb', line 4 def payment_source_class Spree::CreditCard end |
#purchase(_amount, source, gateway_options) ⇒ ActiveMerchant::Billing::Response
Purchases the payment to Komerci
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/models/spree/payment_method/komerci.rb', line 14 def purchase(_amount, source, ) if [:portions].nil? return ActiveMerchant::Billing::Response.new(false, Spree.t('komerci.messages.invalid_portions'), {}, {}) end if [:portions] == 1 transaction = '04' portions = '00' else transaction = Spree::KomerciConfig[:portions_type] portions = [:portions] end params = source, params[:transacao] = transaction params[:parcelas] = portions response = Spree::KomerciConfig. params (source, , response, 'purchase') end |
#void(response_code, _gateway_options) ⇒ ActiveMerchant::Billing::Response
Voids the payment
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/spree/payment_method/komerci.rb', line 110 def void(response_code, ) transaction = Spree::KomerciTransaction.find_by order_number: response_code params = { total: transaction.total, filiacao: Spree::KomerciConfig[:afiliation_key], numcv: transaction.order_number, numautor: transaction., usr: Spree::KomerciConfig[:komerci_user], pwd: Spree::KomerciConfig[:komerci_password], concentrador: nil } response = Spree::KomerciConfig.void_transaction params if response[:success] == true ActiveMerchant::Billing::Response.new(true, Spree.t('komerci.messages.void_success'), {}, authorization: response_code) else = response[:data][:error_number] ? "#{response[:data][:error_number]}: " : '' << response[:data][:error_message] ActiveMerchant::Billing::Response.new(false, , {}, authorization: response_code) end end |