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, 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:) ⇒ 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
118 119 120 121 122 123 |
# File 'lib/mp_api/client.rb', line 118 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, token: nil, issuer_id: nil, installments: nil, three_d_secure_mode: false) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mp_api/client.rb', line 25 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, 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, 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
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/mp_api/client.rb', line 102 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, 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:) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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:) 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 } } }.compact post("/payments", body:) end |
#create_refund(id:, amount:) ⇒ Object
129 130 131 132 133 134 |
# File 'lib/mp_api/client.rb', line 129 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
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mp_api/client.rb', line 48 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
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/mp_api/client.rb', line 72 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 } } post("/card_tokens", body:) end |
#delete_card(customer_id:, card_id:) ⇒ Object
125 126 127 |
# File 'lib/mp_api/client.rb', line 125 def delete_card(customer_id:, card_id:) delete("/customers/#{customer_id}/cards/#{card_id}") end |
#get_customer(email) ⇒ Object
98 99 100 |
# File 'lib/mp_api/client.rb', line 98 def get_customer(email) get("/customers/search?email=#{email}") end |
#get_payment(payment_id) ⇒ Object
61 62 63 |
# File 'lib/mp_api/client.rb', line 61 def get_payment(payment_id) get("/payments/#{payment_id}") end |
#get_payment_methods ⇒ Object
94 95 96 |
# File 'lib/mp_api/client.rb', line 94 def get_payment_methods get("/payment_methods") end |
#get_refund(payment_id:, refund_id:) ⇒ Object
136 137 138 |
# File 'lib/mp_api/client.rb', line 136 def get_refund(payment_id:, refund_id:) get("/payments/#{payment_id}/refunds/#{refund_id}") end |
#search_payment_methods(first_six_digits:) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/mp_api/client.rb', line 85 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
65 66 67 68 69 70 |
# File 'lib/mp_api/client.rb', line 65 def update_payment(payment_id:, status:) body = { status: status } put("/payments/#{payment_id}", body:) end |