Sha256: b983ff4c244f6af6ea83a1a0d0686a2c92a35a34788f52e0cd5ddd59501e046c
Contents?: true
Size: 1.77 KB
Versions: 4
Compression:
Stored size: 1.77 KB
Contents
module SolidusMp class MpPix < Spree::PaymentMethod preference :public_key, :string preference :access_token, :string preference :callback_url, :string def payment_source_class PixPaymentSource end def gateway_class "MpPix" end def supports?(source) source.is_a?(payment_source_class) end def create_api_payment payment begin MpApi.configuration.access_token = preferences[:access_token] mp_payment = MpApi::Payment.new(payer_email: payment.source.email, payer_identification_type: "CPF", payment_method: "pix", payer_identification_number: payment.source.tax_id, amount: payment.amount.to_f).create payment.source.update(external_id: mp_payment.id, qr_code: mp_payment.qr_code, qr_code_base64: mp_payment.qr_code_base_64, ticket_url: mp_payment.ticket_url) rescue MpApi::TooManyRequestsError payment.invalidate end end def authorize(money, source, options = {}) purchase(money, source, options) end def purchase(money, source, options = {}) MpApi.configuration.access_token = preferences[:access_token] mp_payment = MpApi::Payment.find_by_id(source.external_id) if mp_payment.status == "approved" successful_response("Transaction Accredited", mp_payment.id) else failure_response(mp_payment.status_detail || mp_payment.status) end end def partial_name 'mercado_pago_pix' end def successful_response message, transaction_id ActiveMerchant::Billing::Response.new( true, message, {}, authorization: transaction_id ) end def failure_response message ActiveMerchant::Billing::Response.new( false, message ) end end end
Version data entries
4 entries across 4 versions & 1 rubygems