Class: MpApi::Client
- Inherits:
-
Ac::Base
- Object
- Ac::Base
- MpApi::Client
- Defined in:
- lib/mp_api/client.rb
Constant Summary collapse
- BASE_URL =
"https://api.mercadopago.com/v1/"- MAX_RETRIES =
1- SAVE_RESPONSES =
true
Instance Method Summary collapse
- #create_card(customer_id:, token:) ⇒ Object
- #create_credit_card_payment(date_of_expiration: nil, amount:, description: nil, statement_descriptor: nil, payment_method:, payer_email:, payer_identification_type:, payer_identification_number:, capture: nil, external_reference: nil, token: nil, issuer_id: nil, installments: nil, three_d_secure_mode: false) ⇒ Object
- #create_customer(email:, first_name: nil, identification_type:, identification_number:, phone_area_code: "55", phone_number: nil) ⇒ Object
- #create_pix_payment(date_of_expiration: nil, amount:, description: nil, statement_descriptor: nil, payment_method:, payer_email:, payer_identification_type:, payer_identification_number:, external_reference: nil) ⇒ Object
- #create_refund(id:, amount:) ⇒ Object
- #create_saved_credit_card_payment(amount:, token: nil, installments: nil, customer_id: nil) ⇒ Object
- #create_token(card_number:, expiration_year:, expiration_month:, security_code:, cardholder_name:) ⇒ Object
- #delete_card(customer_id:, card_id:) ⇒ Object
- #get_customer(email) ⇒ Object
- #get_payment(payment_id) ⇒ Object
- #get_payment_methods ⇒ Object
- #get_refund(payment_id:, refund_id:) ⇒ Object
- #search_payment_methods(first_six_digits:) ⇒ Object
- #update_payment(payment_id:, status:) ⇒ Object
Instance Method Details
#create_card(customer_id:, token:) ⇒ Object
120 121 122 123 124 125 |
# File 'lib/mp_api/client.rb', line 120 def create_card(customer_id:, token:) body = { token: token } post("/customers/#{customer_id}/cards", body:) end |
#create_credit_card_payment(date_of_expiration: nil, amount:, description: nil, statement_descriptor: nil, payment_method:, payer_email:, payer_identification_type:, payer_identification_number:, capture: nil, external_reference: nil, token: nil, issuer_id: nil, installments: nil, three_d_secure_mode: false) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mp_api/client.rb', line 26 def create_credit_card_payment(date_of_expiration: nil, amount:, description: nil, statement_descriptor: nil, payment_method:, payer_email:, payer_identification_type:, payer_identification_number:, capture: nil, external_reference: nil, token: nil, issuer_id: nil, installments: nil, three_d_secure_mode: false) body = { date_of_expiration: date_of_expiration, transaction_amount: amount, description: description, statement_descriptor: statement_descriptor, payment_method_id: payment_method, payer: { email: payer_email, identification: { type: payer_identification_type, number: payer_identification_number } }, capture: capture, external_reference: external_reference, token: token, issuer_id: issuer_id, installments: installments, three_d_secure_mode: three_d_secure_mode ? "optional" : "not_supported" }.compact post("/payments", body:) end |
#create_customer(email:, first_name: nil, identification_type:, identification_number:, phone_area_code: "55", phone_number: nil) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/mp_api/client.rb', line 104 def create_customer(email:, first_name: nil, identification_type:, identification_number:, phone_area_code: "55", phone_number: nil) body = { email: email, first_name: first_name&.gsub(/[^a-z A-Z]/, ""), identification: { type: identification_type, number: identification_number }, phone: { area_code: phone_area_code, number: phone_number } } post("/customers", body:) end |
#create_pix_payment(date_of_expiration: nil, amount:, description: nil, statement_descriptor: nil, payment_method:, payer_email:, payer_identification_type:, payer_identification_number:, external_reference: nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mp_api/client.rb', line 7 def create_pix_payment(date_of_expiration: nil, amount:, description: nil, statement_descriptor: nil, payment_method:, payer_email:, payer_identification_type:, payer_identification_number:, external_reference: nil) body = { date_of_expiration: date_of_expiration, transaction_amount: amount, description: description, statement_descriptor: statement_descriptor, payment_method_id: payment_method, payer: { email: payer_email, identification: { type: payer_identification_type, number: payer_identification_number } }, external_reference: external_reference }.compact post("/payments", body:) end |
#create_refund(id:, amount:) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/mp_api/client.rb', line 131 def create_refund(id:, amount:) body = { amount: amount } post("/payments/#{id}/refunds", body:) end |
#create_saved_credit_card_payment(amount:, token: nil, installments: nil, customer_id: nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mp_api/client.rb', line 50 def create_saved_credit_card_payment(amount:, token: nil, installments: nil, customer_id: nil) body = { transaction_amount: amount, token: token, installments: installments, payer: { type: "customer", id: customer_id } } post("/payments", body:) end |
#create_token(card_number:, expiration_year:, expiration_month:, security_code:, cardholder_name:) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/mp_api/client.rb', line 74 def create_token(card_number:, expiration_year:, expiration_month:, security_code:, cardholder_name:) body = { card_number: card_number, expiration_year: expiration_year, expiration_month: expiration_month, security_code: security_code, cardholder: { name: cardholder_name.gsub(/[^a-z A-Z]/, "") } } post("/card_tokens", body:) end |
#delete_card(customer_id:, card_id:) ⇒ Object
127 128 129 |
# File 'lib/mp_api/client.rb', line 127 def delete_card(customer_id:, card_id:) delete("/customers/#{customer_id}/cards/#{card_id}") end |
#get_customer(email) ⇒ Object
100 101 102 |
# File 'lib/mp_api/client.rb', line 100 def get_customer(email) get("/customers/search?email=#{email}") end |
#get_payment(payment_id) ⇒ Object
63 64 65 |
# File 'lib/mp_api/client.rb', line 63 def get_payment(payment_id) get("/payments/#{payment_id}") end |
#get_payment_methods ⇒ Object
96 97 98 |
# File 'lib/mp_api/client.rb', line 96 def get_payment_methods get("/payment_methods") end |
#get_refund(payment_id:, refund_id:) ⇒ Object
138 139 140 |
# File 'lib/mp_api/client.rb', line 138 def get_refund(payment_id:, refund_id:) get("/payments/#{payment_id}/refunds/#{refund_id}") end |
#search_payment_methods(first_six_digits:) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/mp_api/client.rb', line 87 def search_payment_methods(first_six_digits:) body = { marketplace: "NONE", status: "active", bins: first_six_digits } get("/payment_methods/search", params: body) end |
#update_payment(payment_id:, status:) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/mp_api/client.rb', line 67 def update_payment(payment_id:, status:) body = { status: status } put("/payments/#{payment_id}", body:) end |