Class: PaymentMethod::CieloDebt
- Inherits:
-
PaymentMethod
- Object
- PaymentMethod
- PaymentMethod::CieloDebt
- Defined in:
- app/models/spree/payment_method/cielo_debt.rb
Instance Method Summary collapse
-
#authorize(_amount, source, _gateway_options) ⇒ ActiveMerchant::Billing::Response
Authorizes the payment to Cielo.
- #auto_capture? ⇒ Boolean
-
#capture(_amount, response_code, _gateway_options) ⇒ ActiveMerchant::Billing::Response
Authorizes the payment to Cielo.
-
#create(amount, source) ⇒ Hash
Creates the transaction to Cielo and return the url of authentication.
- #payment_source_class ⇒ Object
-
#purchase(_amount, source, _gateway_options) ⇒ ActiveMerchant::Billing::Response
Purchases the payment to Cielo.
-
#void(response_code, _gateway_options) ⇒ ActiveMerchant::Billing::Response
Authorizes the payment to Cielo.
Instance Method Details
#authorize(_amount, source, _gateway_options) ⇒ ActiveMerchant::Billing::Response
Authorizes the payment to Cielo
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/models/spree/payment_method/cielo_debt.rb', line 103 def (_amount, source, ) transaction = Cielo::Transaction.new ret = transaction.verify!(source.gateway_payment_profile_id) if ret[:transacao][:status] == '4' ActiveMerchant::Billing::Response.new(true, Spree.t('cielo.messages.authorize_success'), {}, authorization: ret[:transacao][:tid]) else ActiveMerchant::Billing::Response.new(false, Spree.t('cielo.messages.authorize_fail'), {}, authorization: ret[:transacao][:tid]) end rescue verify_error 'authorize', ret end |
#auto_capture? ⇒ Boolean
158 159 160 |
# File 'app/models/spree/payment_method/cielo_debt.rb', line 158 def auto_capture? true end |
#capture(_amount, response_code, _gateway_options) ⇒ ActiveMerchant::Billing::Response
Authorizes the payment to Cielo
129 130 131 132 133 134 135 136 |
# File 'app/models/spree/payment_method/cielo_debt.rb', line 129 def capture(_amount, response_code, ) transaction = Cielo::Transaction.new ret = transaction.catch!(response_code) ActiveMerchant::Billing::Response.new(true, Spree.t('cielo.messages.capture_success'), {}, authorization: ret[:transacao][:tid]) rescue verify_error 'capture', ret end |
#create(amount, source) ⇒ Hash
Creates the transaction to Cielo and return the url of authentication
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 'app/models/spree/payment_method/cielo_debt.rb', line 20 def create(amount, source) cc_type = source.cc_type cc_type = 'mastercard' if cc_type == 'master' return_url = Spree::Store.current.url return_url << Spree::Core::Engine.routes.url_helpers.cielo_debt_confirm_path(source.id, self.id) params = { numero: source.id, valor: amount, moeda: '986', bandeira: cc_type, parcelas: '1', cartao_numero: source.number, :'url-retorno' => return_url, cartao_validade: "#{source.year}#{source.month}", cartao_seguranca: source.verification_value, cartao_portador: source.name, autorizar: '2', produto: 'A', capturar: 'true' } params[:'soft-descriptor'] = Spree::CieloConfig.soft_descriptor if Spree::CieloConfig.soft_descriptor.present? transaction = Cielo::Transaction.new ret = transaction.create!(params, :store) if ret[:transacao][:status] == '0' {url_auth: ret[:transacao][:'url-autenticacao'], tid: ret[:transacao][:tid]} else {error: Spree.t('cielo.messages.authorize_fail')} end rescue if !ret.nil? and ret.has_key? :erro if ret[:erro][:codigo] == '001' {error: Spree.t('cielo.messages.invalid_message')} else {error: "Cielo: #{ret[:erro][:codigo]} - #{ret[:erro][:mensagem]}"} end else {error: Spree.t('cielo.messages.create_rescue')} end end |
#payment_source_class ⇒ Object
4 5 6 |
# File 'app/models/spree/payment_method/cielo_debt.rb', line 4 def payment_source_class Spree::CreditCard end |
#purchase(_amount, source, _gateway_options) ⇒ ActiveMerchant::Billing::Response
Purchases the payment to Cielo
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/spree/payment_method/cielo_debt.rb', line 77 def purchase(_amount, source, ) transaction = Cielo::Transaction.new ret = transaction.verify!(source.gateway_payment_profile_id) if ret[:transacao][:status] == '6' ActiveMerchant::Billing::Response.new(true, Spree.t('cielo.messages.purchase_success'), {}, authorization: ret[:transacao][:tid]) else ActiveMerchant::Billing::Response.new(false, Spree.t('cielo.messages.purchase_fail'), {}, authorization: ret[:transacao][:tid]) end rescue verify_error 'purchase', ret end |
#void(response_code, _gateway_options) ⇒ ActiveMerchant::Billing::Response
Authorizes the payment to Cielo
149 150 151 152 153 154 155 156 |
# File 'app/models/spree/payment_method/cielo_debt.rb', line 149 def void(response_code, ) transaction = Cielo::Transaction.new ret = transaction.cancel!(response_code) ActiveMerchant::Billing::Response.new(true, Spree.t('cielo.messages.void_success'), {}, authorization: ret[:transacao][:tid]) rescue verify_error 'void', ret end |