forked from mercadopago/sdk-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Order - get capture, refund, cancel, update and delete transaction #6
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
09373c8
feature: new endpoint order and transaction
kelvincarvalhosilva dfaec7f
feat: add test
kelvincarvalhosilva 3c40606
fix: remove puts
kelvincarvalhosilva 2b0674b
feature: new endpoint
kelvincarvalhosilva be46a56
Merge branch 'develop' into feature/new-endpoint-2
kelvincarvalhosilva 1380f48
merge
kelvincarvalhosilva a8c7c40
fix: refactor name
kelvincarvalhosilva 97849d5
fix: test card_token update year
kelvincarvalhosilva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require_relative '../../lib/mercadopago' | ||
|
||
|
||
sdk = Mercadopago::SDK.new('<ACCESS_TOKEN>') | ||
|
||
def cancel_order(sdk) | ||
|
||
order_id = '<ORDER_ID>' | ||
|
||
# Set Custom Headers | ||
custom_headers = { | ||
'X-Idempotency-Key': '<SOME_UNIQUE_VALUE>' | ||
} | ||
custom_request_options = Mercadopago::RequestOptions.new(custom_headers: custom_headers) | ||
|
||
# Send Request | ||
result = sdk.order.cancel(order_id, request_options: custom_request_options) | ||
order = result[:response] | ||
puts result[:status] | ||
puts order['id'] | ||
|
||
rescue MercadoPago::MPApiException => e | ||
puts "Status code: #{e.api_response.status_code}" | ||
puts "Content: #{e.api_response.content}" | ||
rescue StandardError => e | ||
puts e.message | ||
end | ||
|
||
cancel_order(sdk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require_relative '../../lib/mercadopago' | ||
|
||
|
||
sdk = Mercadopago::SDK.new('<ACCESS_TOKEN>') | ||
|
||
def capture_order(sdk) | ||
|
||
order_id = '<ORDER_ID>' | ||
|
||
# Set Custom Headers | ||
custom_headers = { | ||
'X-Idempotency-Key': '<SOME_UNIQUE_VALUE>' | ||
} | ||
custom_request_options = Mercadopago::RequestOptions.new(custom_headers: custom_headers) | ||
|
||
# Send Request | ||
result = sdk.order.capture(order_id, request_options: custom_request_options) | ||
order = result[:response] | ||
puts result[:status] | ||
puts order['id'] | ||
|
||
rescue MercadoPago::MPApiException => e | ||
puts "Status code: #{e.api_response.status_code}" | ||
puts "Content: #{e.api_response.content}" | ||
rescue StandardError => e | ||
puts e.message | ||
end | ||
|
||
capture_order(sdk) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require_relative '../../lib/mercadopago' | ||
|
||
|
||
sdk = Mercadopago::SDK.new('<ACCESS_TOKEN>') | ||
|
||
def refund_order(sdk) | ||
|
||
order_id = '<ORDER_ID>' | ||
|
||
# Set Custom Headers | ||
custom_headers = { | ||
'X-Idempotency-Key': '<SOME_UNIQUE_VALUE>' | ||
} | ||
custom_request_options = Mercadopago::RequestOptions.new(custom_headers: custom_headers) | ||
|
||
# Send Request | ||
result = sdk.order.refund(order_id, request_options: custom_request_options) | ||
order = result[:response] | ||
puts result[:status] | ||
puts order['id'] | ||
|
||
rescue MercadoPago::MPApiException => e | ||
puts "Status code: #{e.api_response.status_code}" | ||
puts "Content: #{e.api_response.content}" | ||
rescue StandardError => e | ||
puts e.message | ||
end | ||
|
||
refund_order(sdk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require_relative '../../../lib/mercadopago' | ||
|
||
sdk = Mercadopago::SDK.new('<ACCESS_TOKEN>') | ||
|
||
def delete_order_transaction(sdk) | ||
# Set Custom Headers | ||
custom_headers = { | ||
'X-Idempotency-Key': '<SOME_UNIQUE_VALUE>' | ||
} | ||
custom_request_options = Mercadopago::RequestOptions.new(custom_headers: custom_headers) | ||
|
||
# Send Request | ||
result = sdk.order_transaction.delete('<ORDER_ID>', '<TRANSACTION_ID>', request_options: custom_request_options) | ||
puts result[:status] | ||
rescue MercadoPago::MPApiException => e | ||
puts "Status code: #{e.api_response.status_code}" | ||
puts "Content: #{e.api_response.content}" | ||
rescue StandardError => e | ||
puts e.message | ||
end | ||
|
||
delete_order_transaction(sdk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require_relative '../../../lib/mercadopago' | ||
|
||
sdk = Mercadopago::SDK.new('<ACCESS_TOKEN>') | ||
|
||
def update_order_transaction(sdk) | ||
# Create Transaction Order Update | ||
request = { | ||
payment_method: { | ||
installments: 5 | ||
} | ||
} | ||
|
||
# Set Custom Headers | ||
custom_headers = { | ||
'X-Idempotency-Key': '<SOME_UNIQUE_VALUE>' | ||
} | ||
custom_request_options = Mercadopago::RequestOptions.new(custom_headers: custom_headers) | ||
|
||
# Send Request | ||
result = sdk.order_transaction.update('<ORDER_ID>', '<TRANSACTION_ID>', request, request_options: custom_request_options) | ||
order = result[:response] | ||
puts order | ||
rescue MercadoPago::MPApiException => e | ||
puts "Status code: #{e.api_response.status_code}" | ||
puts "Content: #{e.api_response.content}" | ||
rescue StandardError => e | ||
puts e.message | ||
end | ||
|
||
update_order_transaction(sdk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[q] Aqui vc só extraiu o
data.to_json
para uma variável? Por que foi necessário colocar o&
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
o é em Ruby é uma validação, não um endereço!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
é um bug @andreagostinho-meli, se eu fizer data.to_json independente se data tiver valor ou nao ele vai tentar fazer o to_json e irá enviar para o payload um valor NULL.
com o & se data estiver nulo ele nao tenta fazer o to_json, é quase um if ternário