-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #256 from mercadopago/feature/add-pse-fields
Add new fields required for PSE payments
- Loading branch information
Showing
10 changed files
with
257 additions
and
5 deletions.
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
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
4 changes: 2 additions & 2 deletions
4
src/main/java/com/mercadopago/client/common/AddressRequest.java
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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/mercadopago/client/payment/PaymentPayerAddressRequest.java
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,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; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/mercadopago/client/payment/PaymentPayerPhoneRequest.java
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,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; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
|
@@ -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 { | ||
|
||
|
@@ -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 { | ||
|
@@ -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(); | ||
|
@@ -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(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/test/java/com/mercadopago/resources/mocks/request/payment/payment_pse.json
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,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" | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
src/test/java/com/mercadopago/resources/mocks/response/payment/payment_pse.json
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,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 | ||
} |