Skip to content

Commit

Permalink
Merge pull request #256 from mercadopago/feature/add-pse-fields
Browse files Browse the repository at this point in the history
Add new fields required for PSE payments
  • Loading branch information
romerosilva-meli authored May 30, 2023
2 parents 6722d4f + 38a34f9 commit 3f18347
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ already.
<dependency>
<groupId>com.mercadopago</groupId>
<artifactId>sdk-java</artifactId>
<version>2.1.10</version>
<version>2.1.11</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.mercadopago</groupId>
<artifactId>sdk-java</artifactId>
<version>2.1.10</version>
<version>2.1.11</version>
<packaging>jar</packaging>

<name>Mercadopago SDK</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/mercadopago/MercadoPagoConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/** Mercado Pago configuration class. */
public class MercadoPagoConfig {

public static final String CURRENT_VERSION = "2.1.10";
public static final String CURRENT_VERSION = "2.1.11";

public static final String PRODUCT_ID = "BC32A7VTRPP001U8NHJ0";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.mercadopago.client.common;

import lombok.Builder;
import lombok.Getter;
import lombok.experimental.SuperBuilder;

/** AddressRequest class. */
@Getter
@Builder
@SuperBuilder
public class AddressRequest {
/** Zip code. */
private final String zipCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mercadopago.client.payment;

import com.mercadopago.client.common.AddressRequest;
import lombok.Getter;
import lombok.experimental.SuperBuilder;

/** Payer's address information. */
@Getter
@SuperBuilder
public class PaymentPayerAddressRequest extends AddressRequest {
/** Neighborhood. */
private String neighborhood;

/** City. */
private String city;

/** Federal Unit (e.g. state or province). */
private String federalUnit;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.mercadopago.client.payment;

import lombok.Builder;
import lombok.Getter;

/** Payer's phone information. */
@Getter
@Builder
public class PaymentPayerPhoneRequest {
/** Area code. */
private String areaCode;

/** Phone number. */
private String number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ public class PaymentPayerRequest {

/** Payer's entity type (only for bank transfers). */
private final String entityType;

/** Payer's address information. */
private PaymentPayerAddressRequest address;

/** Payer's phone information. */
private PaymentPayerPhoneRequest phone;
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class PaymentClientTest extends BaseClientTest {

private final String paymentBoletoJson = "payment/payment_boleto.json";

private final String paymentPseJson = "payment/payment_pse.json";

private final String refundBaseJson = "refund/refund_base.json";

private final String refundListJson = "refund/refund_list.json";
Expand Down Expand Up @@ -207,6 +209,27 @@ public void createBoletoWithDiscountFineInterestSuccess()
payment.getPaymentMethod().getData().getRules().getInterest().getValue());
}

@Test
public void createPsePaymentSuccess() throws MPException, MPApiException, IOException {
Payment payment = createPsePayment();

JsonElement requestPayload =
generateJsonElementFromUriRequest(HTTP_CLIENT_MOCK.getRequestPayload());
JsonElement requestPayloadMock = generateJsonElement(paymentPseJson);

assertEquals(requestPayloadMock, requestPayload);
assertNotNull(payment.getResponse());
assertEquals(CREATED, payment.getResponse().getStatusCode());
assertEquals("pse", payment.getPaymentMethodId());
assertEquals("COP", payment.getCurrencyId());
assertEquals("bank_transfer", payment.getPaymentTypeId());
assertEquals("pending", payment.getStatus());
assertEquals("1009", payment.getTransactionDetails().getFinancialInstitution());
assertEquals(
"https://www.mercadopago.com.co/sandbox/payments/1111/bank_transfer?caller_id=2222&hash=1234",
payment.getTransactionDetails().getExternalResourceUrl());
}

@Test
public void getSuccess() throws IOException, MPException, MPApiException {

Expand Down Expand Up @@ -509,6 +532,10 @@ private Payment createBoletoPayment() throws IOException, MPException, MPApiExce
return this.createPayment("bolbradesco", null);
}

private Payment createPsePayment() throws IOException, MPException, MPApiException {
return this.createPayment("pse", null);
}

private Payment createPayment(String paymentMethod, MPRequestOptions requestOptions)
throws IOException, MPException, MPApiException {
class CreateInfo {
Expand All @@ -527,6 +554,7 @@ protected CreateInfo(String responseFile, Supplier<PaymentCreateRequest> createR
paymentMethods.put("card", new CreateInfo(paymentBaseJson, () -> newCardPayment(false)));
paymentMethods.put("3ds", new CreateInfo(payment3dsJson, () -> newCardPayment(true)));
paymentMethods.put("bolbradesco", new CreateInfo(paymentBoletoJson, this::newBoletoPayment));
paymentMethods.put("pse", new CreateInfo(paymentPseJson, this::newPsePayment));

PaymentCreateRequest paymentCreateRequest =
paymentMethods.get(paymentMethod).createRequestFn.get();
Expand Down Expand Up @@ -860,4 +888,45 @@ private PaymentCreateRequest newBoletoPayment() {
.paymentMethod(paymentMethod)
.build();
}

private PaymentCreateRequest newPsePayment() {
IdentificationRequest identification =
IdentificationRequest.builder().type("C.C.").number("1111111111").build();

PaymentPayerAddressRequest address =
PaymentPayerAddressRequest.builder()
.streetName("streetName")
.streetNumber("streetNumber")
.zipCode("zipCode")
.build();

PaymentPayerPhoneRequest phone =
PaymentPayerPhoneRequest.builder().areaCode("111").number("123456").build();

PaymentPayerRequest payer =
PaymentPayerRequest.builder()
.type("customer")
.email("[email protected]")
.entityType("individual")
.firstName("Test")
.lastName("User")
.identification(identification)
.address(address)
.phone(phone)
.build();

PaymentAdditionalInfoRequest additionalInfo =
PaymentAdditionalInfoRequest.builder().ipAddress("127.0.0.1").build();
PaymentTransactionDetailsRequest transactionDetails =
PaymentTransactionDetailsRequest.builder().financialInstitution("1009").build();

return PaymentCreateRequest.builder()
.payer(payer)
.description("description")
.transactionAmount(new BigDecimal(100))
.transactionDetails(transactionDetails)
.paymentMethodId("pse")
.additionalInfo(additionalInfo)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"additional_info": {
"ip_address": "127.0.0.1"
},
"description": "description",
"payer": {
"type": "customer",
"email": "[email protected]",
"entity_type": "individual",
"first_name": "Test",
"last_name": "User",
"identification": {
"type": "C.C.",
"number": "1111111111"
},
"address": {
"street_name": "streetName",
"street_number": "streetNumber",
"zip_code": "zipCode"
},
"phone": {
"area_code": "111",
"number": "123456"
}
},
"payment_method_id": "pse",
"transaction_amount": 100,
"transaction_details": {
"financial_institution": "1009"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"id": 111,
"date_created": "2023-03-08T09:45:24.038-04:00",
"date_approved": null,
"date_last_updated": "2023-03-08T09:45:24.038-04:00",
"date_of_expiration": null,
"money_release_date": null,
"money_release_status": null,
"operation_type": "regular_payment",
"issuer_id": null,
"payment_method_id": "pse",
"payment_type_id": "bank_transfer",
"payment_method": {
"id": "pse",
"type": "bank_transfer"
},
"status": "pending",
"status_detail": "pending_waiting_transfer",
"currency_id": "COP",
"description": "description",
"live_mode": false,
"sponsor_id": null,
"authorization_code": null,
"money_release_schema": null,
"taxes_amount": 0,
"counter_currency": null,
"brand_id": null,
"shipping_amount": 0,
"build_version": "2.136.0",
"pos_id": null,
"store_id": null,
"integrator_id": null,
"platform_id": null,
"corporation_id": null,
"payer": {
"first_name": null,
"last_name": null,
"email": "[email protected]",
"identification": {
"number": "111111",
"type": "DNI"
},
"phone": {
"area_code": null,
"number": null,
"extension": null
},
"type": null,
"entity_type": null,
"id": "11111"
},
"collector_id": 830082116,
"marketplace_owner": null,
"metadata": {},
"additional_info": {
"ip_address": "127.0.0.1",
"available_balance": null,
"nsu_processadora": null,
"authentication_code": null
},
"order": {},
"external_reference": null,
"transaction_amount": 5000,
"net_amount": null,
"taxes": [
{
"value": null,
"type": "IVA"
}
],
"transaction_amount_refunded": 0,
"coupon_amount": 0,
"differential_pricing_id": null,
"financing_group": null,
"deduction_schema": null,
"callback_url": "http://your-site.com",
"installments": 1,
"transaction_details": {
"payment_method_reference_id": null,
"acquirer_reference": null,
"net_received_amount": 0,
"total_paid_amount": 5000,
"overpaid_amount": 0,
"external_resource_url": "https://www.mercadopago.com.co/sandbox/payments/1111/bank_transfer?caller_id=2222&hash=1234",
"installment_amount": 0,
"financial_institution": "1009",
"payable_deferral_period": null,
"bank_transfer_id": 153030,
"transaction_id": "111"
},
"fee_details": [],
"charges_details": [],
"captured": true,
"binary_mode": false,
"call_for_authorize_id": null,
"statement_descriptor": null,
"card": {},
"notification_url": "http://your-site.com",
"refunds": [],
"processing_mode": "aggregator",
"merchant_account_id": null,
"merchant_number": null,
"acquirer_reconciliation": [],
"point_of_interaction": {
"type": "UNSPECIFIED",
"business_info": {
"unit": "online_payments",
"sub_unit": "default"
}
},
"tags": null
}

0 comments on commit 3f18347

Please sign in to comment.