Class: PaymentMethod::CieloCredit
- Inherits:
-
PaymentMethod
- Object
- PaymentMethod
- PaymentMethod::CieloCredit
- Defined in:
- app/models/spree/payment_method/cielo_credit.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 Cielo.
-
#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
65 66 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 103 104 105 106 107 108 |
# File 'app/models/spree/payment_method/cielo_credit.rb', line 65 def (amount, source, ) if [:portions].nil? return ActiveMerchant::Billing::Response.new(false, Spree.t('cielo.messages.invalid_portions'), {}, {}) end total_value = update_payment_amount amount, total_value.delete!('.') default_params = { parcelas: [:portions], capturar: 'false' } if source.gateway_customer_profile_id? params = { token: CGI.escape(source.gateway_customer_profile_id) } else params = { cartao_numero: source.number, cartao_validade: "#{source.year}#{source.month}", cartao_seguranca: source.verification_value, cartao_portador: source.name } if Spree::CieloConfig.generate_token params[:'gerar-token'] = 'true' end end transaction_params = mount_params(total_value, source, params.merge!(default_params)) transaction = Cielo::Transaction.new response = transaction.create!(transaction_params, :store) if response[:transacao][:status] == '4' if Spree::CieloConfig.generate_token storage_token source, response[:transacao] end ActiveMerchant::Billing::Response.new(true, Spree.t('cielo.messages.authorize_success'), {}, authorization: response[:transacao][:tid]) else ActiveMerchant::Billing::Response.new(false, Spree.t('cielo.messages.authorize_fail'), {}, authorization: response[:transacao][:tid]) end rescue verify_error 'authorize', response end |
#cancel(response_code) ⇒ ActiveMerchant::Billing::Response
Cancel the payment
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'app/models/spree/payment_method/cielo_credit.rb', line 146 def cancel(response_code) transaction = Cielo::Transaction.new response = transaction.verify!(response_code) if response[:transacao][:status] == '4' or response[:transacao][:status] == '6' response_cancel = transaction.cancel!(response_code) if response_cancel[:transacao].present? ActiveMerchant::Billing::Response.new(true, Spree.t('cielo.messages.cancel_success'), {}, authorization: response_cancel[:transacao][:tid]) else verify_error 'cancel', response_cancel end else ActiveMerchant::Billing::Response.new(true, Spree.t('cielo.messages.cancel_success'), {}, authorization: response[:transacao][:tid]) end rescue verify_error 'cancel', response end |
#capture(_amount, response_code, _gateway_options) ⇒ ActiveMerchant::Billing::Response
Captures the payment
116 117 118 119 120 121 122 123 |
# File 'app/models/spree/payment_method/cielo_credit.rb', line 116 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 |
#payment_source_class ⇒ Object
4 5 6 |
# File 'app/models/spree/payment_method/cielo_credit.rb', line 4 def payment_source_class Spree::CreditCard end |
#purchase(amount, source, gateway_options) ⇒ ActiveMerchant::Billing::Response
Purchases the payment to Cielo
14 15 16 17 18 19 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 |
# File 'app/models/spree/payment_method/cielo_credit.rb', line 14 def purchase(amount, source, ) if [:portions].nil? return ActiveMerchant::Billing::Response.new(false, Spree.t('cielo.messages.invalid_portions'), {}, {}) end total_value = update_payment_amount amount, total_value.delete!('.') default_params = { parcelas: [:portions], capturar: 'true' } if source.gateway_customer_profile_id? params = { token: CGI.escape(source.gateway_customer_profile_id) } else params = { cartao_numero: source.number, cartao_validade: "#{source.year}#{source.month}", cartao_seguranca: source.verification_value, cartao_portador: source.name } if Spree::CieloConfig.generate_token params[:'gerar-token'] = 'true' end end transaction_params = mount_params(total_value, source, params.merge!(default_params)) transaction = Cielo::Transaction.new response = transaction.create!(transaction_params, :store) if response[:transacao][:status] == '6' if Spree::CieloConfig.generate_token storage_token source, response[:transacao] end ActiveMerchant::Billing::Response.new(true, Spree.t('cielo.messages.purchase_success'), {}, authorization: response[:transacao][:tid]) else ActiveMerchant::Billing::Response.new(false, Spree.t('cielo.messages.purchase_fail'), {}, authorization: response[:transacao][:tid]) end rescue verify_error 'purchase', response end |
#void(response_code, _gateway_options) ⇒ ActiveMerchant::Billing::Response
Voids the payment
131 132 133 134 135 136 137 138 |
# File 'app/models/spree/payment_method/cielo_credit.rb', line 131 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 |