Class: SolidusInter::InterPix
- Inherits:
-
Spree::PaymentMethod
- Object
- Spree::PaymentMethod
- SolidusInter::InterPix
- Defined in:
- app/models/solidus_inter/inter_pix.rb
Instance Method Summary collapse
- #auto_capture? ⇒ Boolean
- #create_payment(order) ⇒ Object
- #find_payment(txid) ⇒ Object
- #gateway_class ⇒ Object
- #invalidate_payment(payment) ⇒ Object
- #partial_name ⇒ Object
- #pay_test_payment(payment, amount: nil) ⇒ Object
- #payment_source_class ⇒ Object
- #payment_valid?(payment) ⇒ Boolean
-
#pix_paid?(payment) ⇒ Boolean
Não da pra chamar o sync aqui pq ele da payment.complete e isso faz nao chamar o purchase.
- #purchase(money, source, _options = {}) ⇒ Object
- #refund_payment(payment) ⇒ Object
- #supports?(source) ⇒ Boolean
Instance Method Details
#auto_capture? ⇒ Boolean
24 25 26 |
# File 'app/models/solidus_inter/inter_pix.rb', line 24 def auto_capture? true end |
#create_payment(order) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/solidus_inter/inter_pix.rb', line 36 def create_payment(order) existing_payment = find_existing_payment(order) return existing_payment if payment_is_usable?(existing_payment, order) invalidate_valid_payments(order, existing_payment&.id) payment = order.payments.new(amount: order.total, payment_method: self) payment.source = init_source(order) payment.save inter_payment = create_inter_payment(payment.source) process_payment_response(payment, inter_payment) payment end |
#find_payment(txid) ⇒ Object
32 33 34 |
# File 'app/models/solidus_inter/inter_pix.rb', line 32 def find_payment(txid) inter_client.get_payment(txid) end |
#gateway_class ⇒ Object
16 17 18 |
# File 'app/models/solidus_inter/inter_pix.rb', line 16 def gateway_class Gateway end |
#invalidate_payment(payment) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/solidus_inter/inter_pix.rb', line 50 def invalidate_payment(payment) txid = payment.source&.txid return false if txid.nil? inter_payment = find_payment(payment.source.txid) sync(payment, inter_payment) return false unless payment.checkout? inter_payment = inter_client.update_payment(payment_id: txid, status: "REMOVIDA_PELO_USUARIO_RECEBEDOR") sync(payment, inter_payment) end |
#partial_name ⇒ Object
28 29 30 |
# File 'app/models/solidus_inter/inter_pix.rb', line 28 def partial_name "inter_pix" end |
#pay_test_payment(payment, amount: nil) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/solidus_inter/inter_pix.rb', line 61 def pay_test_payment(payment, amount: nil) return false unless inter_client.class == InterClientSandbox amount ||= payment.amount txid = payment.source&.txid return false if txid.nil? inter_payment = find_payment(payment.source.txid) sync(payment, inter_payment) return false unless payment.checkout? inter_client.pay_pix(payment_id: payment.source.txid, amount: amount) sync(payment, inter_payment) end |
#payment_source_class ⇒ Object
12 13 14 |
# File 'app/models/solidus_inter/inter_pix.rb', line 12 def payment_source_class PixPaymentSource end |
#payment_valid?(payment) ⇒ Boolean
93 94 95 96 97 |
# File 'app/models/solidus_inter/inter_pix.rb', line 93 def payment_valid? payment return false unless payment.source&.txid purchase(payment) payment.checkout? end |
#pix_paid?(payment) ⇒ Boolean
Não da pra chamar o sync aqui pq ele da payment.complete e isso faz nao chamar o purchase
86 87 88 89 90 91 |
# File 'app/models/solidus_inter/inter_pix.rb', line 86 def pix_paid? payment return false unless payment.source&.txid inter_payment = find_payment(payment.source.txid) paid_amount = total_paid(inter_payment) inter_payment.status == "CONCLUIDA" && paid_amount >= payment.amount end |
#purchase(money, source, _options = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'app/models/solidus_inter/inter_pix.rb', line 75 def purchase(money, source, = {}) inter_payment = source.retrieve_from_api sync(source.payments.sole, inter_payment) if inter_payment.status == "CONCLUIDA" successful_response("Pagamento realizado", status: source.status, internal_detail: "") else failure_response("Pagamento não realizado", status: source.status, internal_detail: "") end end |
#refund_payment(payment) ⇒ Object
99 100 101 |
# File 'app/models/solidus_inter/inter_pix.rb', line 99 def refund_payment(payment) inter_client.refund_payment(end_to_end_id: payment.source.e2e_id, amount: payment.source.paid_amount) end |
#supports?(source) ⇒ Boolean
20 21 22 |
# File 'app/models/solidus_inter/inter_pix.rb', line 20 def supports?(source) source.is_a?(payment_source_class) end |