Skip to content
Draft
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
25 changes: 15 additions & 10 deletions src/main/java/com/univapay/sdk/SDKMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@
import com.univapay.sdk.models.response.subscription.FullSubscription;
import com.univapay.sdk.models.response.transactiontoken.TokenAliasKey;
import com.univapay.sdk.settings.AbstractSDKSettings;
import com.univapay.sdk.types.BusinessType;
import com.univapay.sdk.types.PaymentTypeName;
import com.univapay.sdk.types.RefundReason;
import com.univapay.sdk.types.SubscriptionPeriod;
import com.univapay.sdk.types.TransactionTokenType;
import com.univapay.sdk.types.*;
import java.math.BigInteger;
import java.net.URL;
import java.util.List;
Expand Down Expand Up @@ -210,7 +206,7 @@ AbstractAuthenticationBuilders.AbstractLoginRequestBuilder getLoginToken(
* Get the checkout information for the merchant.
*
* @param origin a domain included in the list of domains associated with the <code>
* application token</code>
* application token</code>
* @return a request builder
*/
AbstractStoreBuilders.AbstractGetCheckoutInfoRequestBuilder getCheckoutInfo(Domain origin);
Expand All @@ -222,6 +218,15 @@ AbstractAuthenticationBuilders.AbstractLoginRequestBuilder getLoginToken(
*/
AbstractStoreBuilders.AbstractGetCheckoutInfoRequestBuilder getCheckoutInfo();

/**
* Get the supported brands for a gateway, required when the Supported Brand at the CheckoutInfo,
* has the dynamic_info: true
*
* @return a request builder
*/
AbstractStoreBuilders.AbstractGetDynamicBrandInfoRequestBuilder getDynamicBrandInfo(
Gateway gateway);

/**
* List the application tokens available for the store with ID <code>storeId</code>.
*
Expand Down Expand Up @@ -349,7 +354,7 @@ AbstractApplicationTokenBuilders.AbstractDeleteStoreApplicationJWTRequestBuilder
*
* @param storeId (optional) the ID of the store for which charges are being requested
* @return an instance of <code>ListChargesRequestBuilder</code> implementing <code>Paginator
* </code>
* </code>
* @see Paginator
*/
AbstractChargesBuilders.AbstractListChargesRequestBuilder listCharges(StoreId storeId);
Expand All @@ -358,7 +363,7 @@ AbstractApplicationTokenBuilders.AbstractDeleteStoreApplicationJWTRequestBuilder
* Obtain a list of charges made by the merchant.
*
* @return an instance of <code>ListChargesRequestBuilder</code> implementing <code>Paginator
* </code>
* </code>
* @see Paginator
*/
AbstractChargesBuilders.AbstractListChargesRequestBuilder listCharges();
Expand Down Expand Up @@ -539,7 +544,7 @@ AbstractChargesBuilders.AbstractUpdateChargeRequestBuilder updateCharge(
* Obtain a list of all the subscriptions.
*
* @return a request builder that implements <code>ListSubscriptionsRequest</code> and <code>
* Paginator</code>
* Paginator</code>
* @see Paginator
*/
AbstractSubscriptionBuilders.AbstractListSubscriptionsMerchantRequestBuilder listSubscriptions();
Expand All @@ -549,7 +554,7 @@ AbstractChargesBuilders.AbstractUpdateChargeRequestBuilder updateCharge(
*
* @param storeId the ID of the store for which subscriptions will be listed
* @return a request builder that implements <code>ListSubscriptionsRequest</code> and <code>
* Paginator</code>
* Paginator</code>
* @see Paginator
*/
AbstractSubscriptionBuilders.AbstractListSubscriptionsRequestBuilder listSubscriptions(
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/univapay/sdk/UnivapaySDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@
import com.univapay.sdk.models.response.transactiontoken.TokenAliasKey;
import com.univapay.sdk.settings.AbstractSDKSettings;
import com.univapay.sdk.settings.UnivapaySettings;
import com.univapay.sdk.types.BusinessType;
import com.univapay.sdk.types.PaymentTypeName;
import com.univapay.sdk.types.RefundReason;
import com.univapay.sdk.types.SubscriptionPeriod;
import com.univapay.sdk.types.TransactionTokenType;
import com.univapay.sdk.types.*;
import java.io.Closeable;
import java.io.IOException;
import java.math.BigInteger;
Expand Down Expand Up @@ -279,6 +275,11 @@ public StoreBuilders.GetCheckoutInfoRequestBuilder getCheckoutInfo() {
return new StoreBuilders.GetCheckoutInfoRequestBuilder(retrofit);
}

@Override
public StoreBuilders.GetDynamicBrandInfoRequestBuilder getDynamicBrandInfo(Gateway gateway) {
return new StoreBuilders.GetDynamicBrandInfoRequestBuilder(retrofit, gateway);
}

@Override
public StoreBuilders.CreateCustomerIdRequestBuilder createCustomerId(
StoreId storeId, String customerId) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/univapay/sdk/adapters/JsonAdapters.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,17 @@ public T read(JsonReader in) throws IOException {
}
}
}

public static class OsTypeTypeAdapter extends BrandsTypeAdapters.SimpleEnumTypeAdapter<OsType> {

@Override
protected String getValueOfObject(OsType input) {
return input.getTypeRepresentation();
}

@Override
protected OsType getByValue(String value) {
return OsType.getInstanceByLiteralValueNullable(value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.univapay.sdk.UnivapaySDK;
import com.univapay.sdk.builders.ResourceMonitor;
import com.univapay.sdk.builders.ResourcePredicate;
import com.univapay.sdk.builders.charge.AbstractChargesBuilders.*;
import com.univapay.sdk.models.common.*;
import com.univapay.sdk.models.common.ChargeId;
Expand Down Expand Up @@ -131,12 +130,7 @@ public static ResourceMonitor<Charge> createChargeCompletionMonitor(
Retrofit retrofit, StoreId storeId, ChargeId chargeId) {
return new ResourceMonitor<>(
new GetChargeRequestBuilder(retrofit, storeId, chargeId).withPolling(true),
new ResourcePredicate<Charge>() {
@Override
public boolean test(Charge resource) {
return resource.getStatus() != ChargeStatus.PENDING;
}
});
resource -> resource.getStatus() != ChargeStatus.PENDING);
}

public static class CreateChargeWithTokenAliasRequestBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.univapay.sdk.models.response.subscription.SubscriptionConfiguration;
import com.univapay.sdk.types.CardBrand;
import com.univapay.sdk.types.Country;
import com.univapay.sdk.types.Gateway;
import java.math.BigDecimal;
import java.net.URL;
import java.time.ZoneId;
Expand Down Expand Up @@ -470,6 +471,37 @@ public AbstractGetCheckoutInfoRequestBuilder(Retrofit retrofit) {
}
}

public abstract static class AbstractGetDynamicBrandInfoRequestBuilder<
B extends AbstractGetDynamicBrandInfoRequestBuilder, R, M extends DynamicBrandInfo>
extends RetrofitRequestBuilder<M, R> {

public AbstractGetDynamicBrandInfoRequestBuilder(Retrofit retrofit) {
super(retrofit);
}

// Parameters for this request

protected Gateway gateway;
protected MoneyLike requestedMoney;
protected CallMethod callMethod;
protected OsType osType;

public B withRequestedMoney(MoneyLike requestedMoney) {
this.requestedMoney = requestedMoney;
return (B) this;
}

public B withCallMethod(CallMethod callMethod) {
this.callMethod = callMethod;
return (B) this;
}

public B withOsType(OsType osType) {
this.osType = osType;
return (B) this;
}
}

public abstract static class AbstractCreateCustomerIdRequestBuilder<
B extends AbstractCreateCustomerIdRequestBuilder, R, M extends UnivapayCustomerId>
extends RetrofitRequestBuilder<M, R> {
Expand Down
31 changes: 28 additions & 3 deletions src/main/java/com/univapay/sdk/builders/store/StoreBuilders.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.univapay.sdk.builders.store;

import com.univapay.sdk.builders.store.AbstractStoreBuilders.*;
import com.univapay.sdk.models.common.Domain;
import com.univapay.sdk.models.common.StoreId;
import com.univapay.sdk.models.common.UnivapayCustomerId;
import com.univapay.sdk.models.common.*;
import com.univapay.sdk.models.common.Void;
import com.univapay.sdk.models.request.configuration.StoreConfigurationRequest;
import com.univapay.sdk.models.request.store.CustomerIdRequest;
import com.univapay.sdk.models.request.store.GetDynamicBrandInfoForm;
import com.univapay.sdk.models.request.store.StoreCreateData;
import com.univapay.sdk.models.response.PaginatedList;
import com.univapay.sdk.models.response.store.CheckoutInfo;
import com.univapay.sdk.models.response.store.DynamicBrandInfo;
import com.univapay.sdk.models.response.store.Store;
import com.univapay.sdk.models.response.store.StoreWithConfiguration;
import com.univapay.sdk.resources.StoresResource;
import com.univapay.sdk.types.Gateway;
import com.univapay.sdk.utils.builders.ConfigurationBuilder;
import retrofit2.Call;
import retrofit2.Retrofit;
Expand Down Expand Up @@ -147,6 +148,30 @@ protected Call<CheckoutInfo> getRequest(StoresResource resource) {
}
}

public static class GetDynamicBrandInfoRequestBuilder
extends AbstractGetDynamicBrandInfoRequestBuilder<
GetDynamicBrandInfoRequestBuilder, StoresResource, DynamicBrandInfo> {

public GetDynamicBrandInfoRequestBuilder(Retrofit retrofit, Gateway gateway) {
super(retrofit);
this.gateway = gateway;
}

@Override
protected Call<DynamicBrandInfo> getRequest(StoresResource resource) {
GetDynamicBrandInfoForm form = new GetDynamicBrandInfoForm();

if (requestedMoney != null) {
form.setRequestedMoney(new GetDynamicBrandInfoForm.RequestMoneyInformation(requestedMoney));
}

form.setCallMethod(callMethod);
form.setOsType(osType);

return resource.getDynamicBrandInfo(gateway, form);
}
}

public static class CreateCustomerIdRequestBuilder
extends AbstractCreateCustomerIdRequestBuilder<
CreateCustomerIdRequestBuilder, StoresResource, UnivapayCustomerId> {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/univapay/sdk/models/common/CallMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
/** Representation of the method that is used to consume the issuerToken */
public enum CallMethod {

/** The issuer token is a HTTP endpoint, invoked with GET */
/** The issuer token is an HTTP endpoint, invoked with GET */
@SerializedName("http_get")
HTTP_GET,
/** The issuer token is a HTTP endpoint, invoked with POST */
/** The issuer token is an HTTP endpoint, invoked with POST */
@SerializedName("http_post")
HTTP_POST,
/** The issuer token should be forwarded to the service's provided SDK */
Expand Down
41 changes: 38 additions & 3 deletions src/main/java/com/univapay/sdk/models/common/OnlinePayment.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,40 @@
public class OnlinePayment implements PaymentData {

/** This defines which service will be used when creating the TransactionToken & Charge */

// Can be a Static brand & or a ConnectWallet dynamic sub brand
@SerializedName("brand")
private final OnlineBrand brand;
private final String brand;

private transient OnlineBrand onlineBrand;

@SerializedName("call_method")
private CallMethod callMethod;

@SerializedName("user_identifier")
private String userIdentifier;

@SerializedName("os_type")
private OsType osType;

@Override
public PaymentTypeName getPaymentType() {
return PaymentTypeName.ONLINE;
}

public OnlinePayment(OnlineBrand brand) {
if (brand != null) {
this.brand = brand.getTypeRepresentation();
} else {
this.brand = null;
}

this.onlineBrand = brand;
}

public OnlinePayment(String brand) {
this.brand = brand;
this.onlineBrand = OnlineBrand.getInstanceByLiteralValueNullable(brand);
}

public OnlinePayment withCallMethod(CallMethod callMethod) {
Expand All @@ -36,8 +54,17 @@ public OnlinePayment withUserIdentifier(String userIdentifier) {
return this;
}

public OnlineBrand getBrand() {
return brand;
public OnlinePayment withOsType(OsType osType) {
this.osType = osType;
return this;
}

public OnlineBrand getOnlineBrand() {
if (onlineBrand == null) {
onlineBrand = OnlineBrand.getInstanceByLiteralValueNullable(brand);
}

return onlineBrand;
}

public CallMethod getCallMethod() {
Expand All @@ -47,4 +74,12 @@ public CallMethod getCallMethod() {
public String getUserIdentifier() {
return userIdentifier;
}

public String getBrand() {
return brand;
}

public OsType getOsType() {
return osType;
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/univapay/sdk/models/common/OsType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.univapay.sdk.models.common;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public enum OsType {
iOS("i_os"),
Android("android");

private final String typeRepresentation;

OsType(String typeRepresentation) {
this.typeRepresentation = typeRepresentation;
}

public String getTypeRepresentation() {
return typeRepresentation;
}

static final Map<String, OsType> entryMapByTypeRepresentation =
Arrays.stream(OsType.values())
.collect(Collectors.toMap(OsType::getTypeRepresentation, Function.identity()));

public static OsType getInstanceByLiteralValue(final String literalValue)
throws IllegalArgumentException {
OsType value = entryMapByTypeRepresentation.get(literalValue);

if (value == null) {
throw new IllegalArgumentException();
} else {
return value;
}
}

public static OsType getInstanceByLiteralValueNullable(final String literalValue) {
return entryMapByTypeRepresentation.get(literalValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.univapay.sdk.models.response.transactiontoken.*;
import com.univapay.sdk.types.Gateway;
import com.univapay.sdk.types.Konbini;
import com.univapay.sdk.types.brand.OnlineBrand;
import com.univapay.sdk.types.brand.QrCpmBrand;
import com.univapay.sdk.types.brand.QrMpmBrand;
import java.lang.reflect.Type;
Expand Down Expand Up @@ -92,7 +91,7 @@ public PaymentData deserialize(JsonElement json, Type type, JsonDeserializationC

QrCpmBrand qrCpmBrand = context.deserialize(object.get("brand"), QrCpmBrand.class);
QrMpmBrand qrMpmBrand = context.deserialize(object.get("brand"), QrMpmBrand.class);
OnlineBrand onlineBrand = context.deserialize(object.get("brand"), OnlineBrand.class);
String onlineBrand = context.deserialize(object.get("brand"), String.class);
CallMethod callMethod = context.deserialize(object.get("call_method"), CallMethod.class);
String issuerToken = asString(object, "issuer_token");
String userIdentifier = asString(object, "user_identifier");
Expand Down
Loading