Class: SolidusMpDois::MpGateway
- Inherits:
-
Object
- Object
- SolidusMpDois::MpGateway
- Defined in:
- app/models/solidus_mp_dois/mp_gateway.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ MpGateway
constructor
A new instance of MpGateway.
- #purchase(money, source, options = {}) ⇒ Object
- #void(transaction_id, options = {}) ⇒ Object
Constructor Details
#initialize(options) ⇒ MpGateway
Returns a new instance of MpGateway.
3 4 5 |
# File 'app/models/solidus_mp_dois/mp_gateway.rb', line 3 def initialize() MpApi.configuration.access_token = [:access_token] end |
Instance Method Details
#purchase(money, source, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/models/solidus_mp_dois/mp_gateway.rb', line 7 def purchase money, source, = {} mp_payment = source.retrieve_from_api 10.times do break if ["approved", "rejected"].include? mp_payment.status mp_payment = source.retrieve_from_api end if mp_payment.status == "approved" source.update(status: "approved") successful_response("Pagamento realizado", mp_payment.id) else failure_response(mp_payment.status_detail || mp_payment.status) end end |
#void(transaction_id, options = {}) ⇒ Object
21 22 23 24 |
# File 'app/models/solidus_mp_dois/mp_gateway.rb', line 21 def void(transaction_id, = {}) # Respondendo sempre com successful_response para funcionar o botão de "Cancelar" do pedido. Reembolso deve ser feito por fora. successful_response("Pagamento cancelado. Se necessário, realize o reembolso.", transaction_id) end |