Skip to content
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

added new params for paypal #331

Merged
merged 9 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/com/mangopay/core/APIs/ApiBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ protected MangoPayApi getRoot() {
put("payins_klarna-web_create", new String[]{"/payins/payment-methods/klarna", RequestType.POST.toString()});
put("payins_ideal-web_create", new String[]{"/payins/payment-methods/ideal", RequestType.POST.toString()});
put("payins_giropay-web_create", new String[]{"/payins/payment-methods/giropay", RequestType.POST.toString()});
put("add_tracking_info", new String[]{"/payins/%s/trackings", RequestType.PUT.toString()});

put("payment_method-metadata", new String[]{"/payment-methods/metadata", RequestType.POST.toString()});

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/mangopay/core/APIs/PayInApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mangopay.core.Sorting;
import com.mangopay.entities.*;
import com.mangopay.entities.subentities.CreateCardPreAuthorizedDepositPayIn;
import com.mangopay.entities.subentities.PayPalWebTracking;

import java.util.List;

Expand Down Expand Up @@ -142,4 +143,17 @@ public interface PayInApi {
* @throws Exception
*/
PaymentMethodMetadata getPaymentMethodMetadata(PaymentMethodMetadata metadata) throws Exception;


/**
* Add tracking information to a PayPal PayIn (add the tracking number and carrier for LineItems shipments.)
* Caution – Tracking information cannot be edited
* You can’t modify the TrackingNumber, Carrier, or NotifyBuyer once added.
* You can only send a unique tracking number once.
*
* @param payInId The ID of the PayIn
* @param trackingData trackingInformation object
* @return {PayIn} object returned by the API
*/
PayIn addPayPalTrackingInformation(String payInId, PayPalWebTracking trackingData) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.mangopay.core.serializer.PayInSerializer;
import com.mangopay.entities.*;
import com.mangopay.entities.subentities.CreateCardPreAuthorizedDepositPayIn;
import com.mangopay.entities.subentities.PayPalWebTracking;

import java.util.List;

Expand Down Expand Up @@ -134,4 +135,9 @@ public PayIn createPayPal(PayIn payIn) throws Exception {
public PaymentMethodMetadata getPaymentMethodMetadata(PaymentMethodMetadata metadata) throws Exception {
return this.createObject(PaymentMethodMetadata.class, null, "payment_method-metadata", metadata);
}

@Override
public PayIn addPayPalTrackingInformation(String payInId, PayPalWebTracking trackingData) throws Exception {
return this.updateObject(PayIn.class, "add_tracking_info", trackingData, payInId);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/mangopay/core/LineItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class LineItem extends Dto{
@SerializedName("Description")
private String description;

@SerializedName("Category")
private String category;

public LineItem(String name, Integer quantity, Integer unitAmount, Integer taxAmount, String description) {
this.name = name;
this.quantity = quantity;
Expand Down Expand Up @@ -87,4 +90,13 @@ public LineItem setDescription(String description) {
this.description = description;
return this;
}

public String getCategory() {
return category;
}

public LineItem setCategory(String category) {
this.category = category;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,33 @@ public PayIn deserialize(JsonElement json, Type typeOfT, JsonDeserializationCont
if (object.has("Reference") && !object.get("Reference").isJsonNull()) {
payInPaymentDetailsPayPal.setReference(object.get("Reference").getAsString());
}
if (object.has("CancelURL") && !object.get("CancelURL").isJsonNull()) {
payInPaymentDetailsPayPal.setCancelUrl(object.get("CancelURL").getAsString());
}
if (object.has("PaypalPayerID") && !object.get("PaypalPayerID").isJsonNull()) {
payInPaymentDetailsPayPal.setPaypalOrderID(object.get("PaypalPayerID").getAsString());
}
if (object.has("BuyerCountry") && !object.get("BuyerCountry").isJsonNull()) {
payInPaymentDetailsPayPal.setBuyerCountry(object.get("BuyerCountry").getAsString());
}
if (object.has("BuyerFirstname") && !object.get("BuyerFirstname").isJsonNull()) {
payInPaymentDetailsPayPal.setBuyerFirstName(object.get("BuyerFirstname").getAsString());
}
if (object.has("BuyerLastname") && !object.get("BuyerLastname").isJsonNull()) {
payInPaymentDetailsPayPal.setBuyerLastName(object.get("BuyerLastname").getAsString());
}
if (object.has("BuyerPhone") && !object.get("BuyerPhone").isJsonNull()) {
payInPaymentDetailsPayPal.setBuyerPhone(object.get("BuyerPhone").getAsString());
}
if (object.has("PaypalOrderID") && !object.get("PaypalOrderID").isJsonNull()) {
payInPaymentDetailsPayPal.setPaypalOrderID(object.get("PaypalOrderID").getAsString());
}
if (object.has("Trackings") && !object.get("Trackings").isJsonNull()) {
Type listType = new TypeToken<ArrayList<PayPalWebTracking>>() {
}.getType();
payInPaymentDetailsPayPal.setTrackings((List<PayPalWebTracking>) context.deserialize(object.get("Trackings"), listType));
}

payIn.setPaymentDetails(payInPaymentDetailsPayPal);
break;
case PAYCONIQ:
Expand Down Expand Up @@ -178,7 +205,8 @@ public PayIn deserialize(JsonElement json, Type typeOfT, JsonDeserializationCont
case KLARNA:
PayInPaymentDetailsKlarna payInPaymentDetailsKlarna = new PayInPaymentDetailsKlarna();
if (object.has("LineItems") && !object.get("LineItems").isJsonNull()) {
Type listType = new TypeToken<ArrayList<LineItem>>(){}.getType();
Type listType = new TypeToken<ArrayList<LineItem>>() {
}.getType();
payInPaymentDetailsKlarna.setLineItems((List<LineItem>) context.deserialize(object.get("LineItems"), listType));
}
if (object.has("Shipping") && !object.get("Shipping").isJsonNull())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public JsonElement serialize(PayIn src, Type typeOfSrc, JsonSerializationContext
object.add("LineItems", context.serialize(((PayInPaymentDetailsPayPal) src.getPaymentDetails()).getLineItems()));
object.add("ShippingPreference", context.serialize(((PayInPaymentDetailsPayPal) src.getPaymentDetails()).getShippingPreference()));
object.add("Reference", context.serialize(((PayInPaymentDetailsPayPal) src.getPaymentDetails()).getReference()));
object.add("CancelURL", context.serialize(((PayInPaymentDetailsPayPal) src.getPaymentDetails()).getCancelUrl()));
object.add("PaypalPayerID", context.serialize(((PayInPaymentDetailsPayPal) src.getPaymentDetails()).getPaypalPayerId()));
object.add("BuyerCountry", context.serialize(((PayInPaymentDetailsPayPal) src.getPaymentDetails()).getBuyerCountry()));
object.add("BuyerFirstname", context.serialize(((PayInPaymentDetailsPayPal) src.getPaymentDetails()).getBuyerFirstName()));
object.add("BuyerLastname", context.serialize(((PayInPaymentDetailsPayPal) src.getPaymentDetails()).getBuyerLastName()));
object.add("BuyerPhone", context.serialize(((PayInPaymentDetailsPayPal) src.getPaymentDetails()).getBuyerPhone()));
object.add("PaypalOrderID", context.serialize(((PayInPaymentDetailsPayPal) src.getPaymentDetails()).getPaypalOrderID()));
object.add("Trackings", context.serialize(((PayInPaymentDetailsPayPal) src.getPaymentDetails()).getTrackings()));
break;
case "PayInPaymentDetailsPayconiq":
object.add("Country", context.serialize(((PayInPaymentDetailsPayconiq) src.getPaymentDetails()).getCountry()));
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/mangopay/entities/CardValidation.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public class CardValidation extends EntityBase {
@SerializedName("SecureModeNeeded")
private String secureModeNeeded;

/**
* The mode applied for the 3DS2 protocol for CB, Visa, and Mastercard
*/
@SerializedName("SecureMode")
private SecureMode secureMode;

@SerializedName("IpAddress")
private String ipAddress;

Expand Down Expand Up @@ -230,6 +236,15 @@ public void setSecureModeReturnUrl(String secureModeReturnUrl) {

public void setApplied3DSVersion(String applied3DSVersion) { this.applied3DSVersion = applied3DSVersion; }

public SecureMode getSecureMode() {
return secureMode;
}

public CardValidation setSecureMode(SecureMode secureMode) {
this.secureMode = secureMode;
return this;
}

/**
* Gets map which property is an object and what type of object.
* To be overridden in child class if has any sub objects.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ public class PayInPaymentDetailsPayPal extends Dto implements PayInPaymentDetail
@SerializedName("ShippingAddress")
private ShippingAddress shippingAddress;

@Deprecated
@SerializedName("PaypalBuyerAccountEmail")
private String paypalBuyerAccountEmail;


/// V2 ///

Expand All @@ -46,6 +42,33 @@ public class PayInPaymentDetailsPayPal extends Dto implements PayInPaymentDetail
@SerializedName("Reference")
private String reference;

@SerializedName("CancelURL")
private String cancelUrl;

@SerializedName("PaypalPayerID")
private String paypalPayerId;

@SerializedName("BuyerCountry")
private String buyerCountry;

@SerializedName("BuyerFirstname")
private String buyerFirstName;

@SerializedName("BuyerLastname")
private String buyerLastName;

@SerializedName("BuyerPhone")
private String buyerPhone;

@SerializedName("PaypalOrderID")
private String paypalOrderID;

@SerializedName("PaypalBuyerAccountEmail")
private String paypalBuyerAccountEmail;

@SerializedName("Trackings")
private List<PayPalWebTracking> trackings;

public ShippingAddress getShippingAddress() {
return shippingAddress;
}
Expand Down Expand Up @@ -81,6 +104,15 @@ public PayInPaymentDetailsPayPal setLineItems(List<LineItem> lineItems) {
return this;
}

public String getCancelUrl() {
return cancelUrl;
}

public PayInPaymentDetailsPayPal setCancelUrl(String cancelUrl) {
this.cancelUrl = cancelUrl;
return this;
}

@Override
public Map<String, Type> getSubObjects() {
Map<String, Type> subObjects = super.getSubObjects();
Expand All @@ -104,15 +136,80 @@ public ShippingPreference getShippingPreference() {
return shippingPreference;
}

public void setShippingPreference(ShippingPreference shippingPreference) {
public PayInPaymentDetailsPayPal setShippingPreference(ShippingPreference shippingPreference) {
this.shippingPreference = shippingPreference;
return this;
}

public String getReference() {
return reference;
}

public void setReference(String reference) {
public PayInPaymentDetailsPayPal setReference(String reference) {
this.reference = reference;
return this;
}

public String getPaypalPayerId() {
return paypalPayerId;
}

public PayInPaymentDetailsPayPal setPaypalPayerId(String paypalPayerId) {
this.paypalPayerId = paypalPayerId;
return this;
}

public String getBuyerCountry() {
return buyerCountry;
}

public PayInPaymentDetailsPayPal setBuyerCountry(String buyerCountry) {
this.buyerCountry = buyerCountry;
return this;
}

public String getBuyerFirstName() {
return buyerFirstName;
}

public PayInPaymentDetailsPayPal setBuyerFirstName(String buyerFirstName) {
this.buyerFirstName = buyerFirstName;
return this;
}

public String getBuyerLastName() {
return buyerLastName;
}

public PayInPaymentDetailsPayPal setBuyerLastName(String buyerLastName) {
this.buyerLastName = buyerLastName;
return this;
}

public String getBuyerPhone() {
return buyerPhone;
}

public PayInPaymentDetailsPayPal setBuyerPhone(String buyerPhone) {
this.buyerPhone = buyerPhone;
return this;
}

public String getPaypalOrderID() {
return paypalOrderID;
}

public PayInPaymentDetailsPayPal setPaypalOrderID(String paypalOrderID) {
this.paypalOrderID = paypalOrderID;
return this;
}

public List<PayPalWebTracking> getTrackings() {
return trackings;
}

public PayInPaymentDetailsPayPal setTrackings(List<PayPalWebTracking> trackings) {
this.trackings = trackings;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.mangopay.entities.subentities;

import com.google.gson.annotations.SerializedName;
import com.mangopay.core.EntityBase;

public class PayPalWebTracking extends EntityBase {

/**
* The shipment’s tracking number provided by the carrier.
*/
@SerializedName("TrackingNumber")
private String trackingNumber;
/**
* The carrier for the shipment. Use the country-specific version of the carrier if it exists,
* otherwise use its global version.
* Returned values: One of the carriers supported by PayPal.
*/
@SerializedName("Carrier")
private String carrier;
/**
* If true, sends an email notification to the PaypalBuyerAccountEmail containing the TrackingNumber and Carrier,
* which allows the end user to track their shipment with the carrier.
* Default value: false
*/
@SerializedName("NotifyBuyer")
private boolean notifyBuyer;

public String getTrackingNumber() {
return trackingNumber;
}

public PayPalWebTracking setTrackingNumber(String trackingNumber) {
this.trackingNumber = trackingNumber;
return this;
}

public String getCarrier() {
return carrier;
}

public PayPalWebTracking setCarrier(String carrier) {
this.carrier = carrier;
return this;
}

public boolean isNotifyBuyer() {
return notifyBuyer;
}

public PayPalWebTracking setNotifyBuyer(boolean notifyBuyer) {
this.notifyBuyer = notifyBuyer;
return this;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/com/mangopay/core/mangopay.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Fri Feb 16 11:11:37 EET 2024
#Wed Mar 27 13:36:37 EET 2024
version=2.36.0
1 change: 1 addition & 0 deletions src/test/java/com/mangopay/core/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,7 @@ protected CardValidation createJohnsCardValidation() throws Exception {

cardValidation.setAuthorId(user.getId());
cardValidation.setSecureModeReturnUrl("http://test.com");
cardValidation.setSecureMode(SecureMode.NO_CHOICE);

cardValidation.setBrowserInfo(getNewBrowserInfo());
cardValidation.setIpAddress("2001:0620:0000:0000:0211:24FF:FE80:C12C");
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/mangopay/core/CardApiImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void validateCard() throws Exception{

assertNotNull(cardValidation);
assertNotNull(cardValidation.getId());
assertNotNull(cardValidation.getSecureMode());
assertEquals(TransactionType.CARD_VALIDATION, cardValidation.getType());
}

Expand Down
Loading
Loading