Skip to content

Commit a80a2c6

Browse files
committed
endpoint patch - update transaction
1 parent ea85e8a commit a80a2c6

File tree

5 files changed

+106
-3
lines changed

5 files changed

+106
-3
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
repos:
22
# Websec hook is MANDATORY, DO NOT comment it.
33
- repo: https://github.com/melisource/fury_websec-git-hooks
4-
rev: v1.1.0
4+
rev: v2.0.0
55
hooks:
66
- id: pre_commit_hook
77
stages: [commit]
@@ -10,8 +10,9 @@ repos:
1010

1111
# Datasec hook is MANDATORY, DO NOT comment it.
1212
- repo: https://github.com/melisource/fury_datasec-git-hooks
13-
rev: 1.0.3
13+
rev: 1.2.1
1414
hooks:
1515
- id: pre_commit_hook
1616
stages: [commit]
17-
verbose: true
17+
- id: post_commit_hook
18+
stages: [post-commit]

src/main/java/com/mercadopago/client/order/OrderClient.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,56 @@ public OrderTransaction createTransaction(String orderId, OrderTransactionReques
201201
throws MPException, MPApiException {
202202
return this.createTransaction(orderId, request, null);
203203
}
204+
205+
/**
206+
* Method responsible for update a transaction by id with request options
207+
*
208+
* @param orderId orderId
209+
* @param transactionId transactionId
210+
* @param requestOptions Metadata to customize the request
211+
* @return The response for the order transaction
212+
* @throws MPException an error if the request fails
213+
* @throws MPApiException an error if the request fails
214+
*/
215+
public OrderTransaction updateTransaction(String orderId, String transactionId, OrderTransactionRequest request,
216+
MPRequestOptions requestOptions) throws MPException, MPApiException {
217+
LOGGER.info("Sending order transaction update request");
218+
219+
if (StringUtils.isBlank(orderId)) {
220+
throw new IllegalArgumentException("Order id cannot be null or empty");
221+
}
222+
223+
if (StringUtils.isBlank(transactionId)) {
224+
throw new IllegalArgumentException("Transaction id cannot be null or empty");
225+
}
226+
227+
String url = String.format(URL_TRANSACTION + "/%s", orderId, transactionId);
228+
229+
MPRequest mpRequest = MPRequest.builder()
230+
.uri(url)
231+
.method(HttpMethod.PUT)
232+
.payload(Serializer.serializeToJson(request))
233+
.build();
234+
235+
MPResponse response = send(mpRequest, requestOptions);
236+
237+
OrderTransaction order = Serializer.deserializeFromJson(OrderTransaction.class, response.getContent());
238+
order.setResponse(response);
239+
240+
return order;
241+
}
242+
/**
243+
* Method responsible for updating a transaction for an order
244+
*
245+
* @param orderId The ID of the order for which the transaction is created
246+
* @param transactionId The ID of the transaction to be updated
247+
* @param request The request object containing transaction details
248+
* @return The response for the order transaction
249+
* @throws MPException an error if the request fails
250+
* @throws MPApiException an error if the request fails
251+
*/
252+
public OrderTransaction updateTransaction(String orderId,String transactionId, OrderTransactionRequest request)
253+
throws MPException, MPApiException {
254+
return this.updateTransaction(orderId, transactionId, request, null);
255+
}
204256
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.mercadopago.example.apis.order;
2+
3+
public class UpdateTransaction {
4+
5+
}

src/test/java/com/mercadopago/client/order/OrderClientTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class OrderClientTest extends BaseClientTest {
2626
//File Mock Responses
2727
private static final String CREATE_ORDER_RESPONSE_FILE = "order/create_order_response.json";
2828
private static final String CREATE_TRANSACTION_RESPONSE_FILE = "order/create_transaction_response.json";
29+
private static final String UPDATE_TRANSACTION_FILE = "order/update_transaction_response.json";
2930

3031
private final OrderClient client = new OrderClient();
3132

@@ -150,4 +151,37 @@ void createTransactionWithRequestOptionsSuccess() throws MPException, MPApiExcep
150151
Assertions.assertEquals("BRL", orderTransaction.getPayments().get(0).getCurrency());
151152
Assertions.assertEquals("master", orderTransaction.getPayments().get(0).getPaymentMethod().getId());
152153
}
154+
155+
@Test
156+
void updateTransactionIntentSuccess() throws MPException, MPApiException, IOException {
157+
HttpResponse response = MockHelper.generateHttpResponseFromFile(UPDATE_TRANSACTION_FILE, HttpStatus.OK);
158+
159+
Mockito.doReturn(response).when(HTTP_CLIENT).execute(any(HttpRequestBase.class), any(HttpContext.class));
160+
161+
String orderId = "123";
162+
String transactionId = "pay_012345";
163+
OrderPaymentRequest paymentRequest = OrderPaymentRequest.builder()
164+
.amount("100.00")
165+
.currency("BRL")
166+
.paymentMethod(OrderPaymentMethodRequest.builder()
167+
.id("master")
168+
.type("credit_card")
169+
.token("some-token")
170+
.installments(1)
171+
.issuerId("701")
172+
.statementDescriptor("statement")
173+
.build())
174+
.build();
175+
176+
OrderTransactionRequest request = OrderTransactionRequest.builder()
177+
.payments(Collections.singletonList(paymentRequest))
178+
.build();
179+
180+
OrderTransaction orderTransaction = client.updateTransaction(orderId, transactionId, request);
181+
182+
Assertions.assertNotNull(orderTransaction);
183+
Assertions.assertEquals("100.00", orderTransaction.getPayments().get(0).getAmount());
184+
Assertions.assertEquals("BRL", orderTransaction.getPayments().get(0).getCurrency());
185+
Assertions.assertEquals("master", orderTransaction.getPayments().get(0).getPaymentMethod().getId());
186+
}
153187
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"id": "pay_012345",
3+
"amount": "100.00",
4+
"payment_method": {
5+
"id": "master",
6+
"type": "credit_card",
7+
"token": "card_token",
8+
"statement_descriptor": "statement",
9+
"installments": 1
10+
}
11+
}

0 commit comments

Comments
 (0)