Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Set NoShipping to 1, When shipping address is missing. #413

Merged
merged 3 commits into from
Sep 13, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public class AuthorizationRequest extends BaseRequest {

private String backurl;


protected AuthorizationRequest(final PayoneConfig config, final String requestType, final String clearingtype) {
super(config, requestType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ public class WalletAuthorizationRequest extends AuthorizationRequest {

private String wallettype;

public WalletAuthorizationRequest(final PayoneConfig config, final ClearingType clearingType) {
private int noShipping;

public WalletAuthorizationRequest(final PayoneConfig config, final ClearingType clearingType, final int noShipping) {
super(config, RequestType.AUTHORIZATION.getType(), clearingType.getPayoneCode());

this.wallettype = clearingType.getSubType();
this.noShipping = noShipping;
}

//**************************************************************
Expand All @@ -27,4 +30,8 @@ public WalletAuthorizationRequest(final PayoneConfig config, final ClearingType
public String getWallettype() {
return wallettype;
}

public int getNoShipping() {
return noShipping;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ public class WalletPreauthorizationRequest extends AuthorizationRequest {

private String wallettype;

public WalletPreauthorizationRequest(final PayoneConfig config, final ClearingType clearingType) {
private int noShipping;
butenkor marked this conversation as resolved.
Show resolved Hide resolved

public WalletPreauthorizationRequest(final PayoneConfig config, final ClearingType clearingType, final int noShipping) {
super(config, RequestType.PREAUTHORIZATION.getType(), clearingType.getPayoneCode());

this.wallettype = clearingType.getSubType();
this.noShipping = noShipping;
}

//**************************************************************
Expand All @@ -27,4 +30,9 @@ public WalletPreauthorizationRequest(final PayoneConfig config, final ClearingTy
public String getWallettype() {
return wallettype;
}

public int getNoShipping() {
return noShipping;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.commercetools.pspadapter.payone.mapping;

import com.commercetools.pspadapter.payone.domain.ctp.PaymentWithCartLike;
import com.commercetools.pspadapter.payone.domain.ctp.paymentmethods.MethodKeys;
import com.commercetools.pspadapter.payone.domain.payone.model.common.AuthorizationRequest;
import com.neovisionaries.i18n.CountryCode;
import io.sphere.sdk.carts.CartLike;
Expand Down Expand Up @@ -127,25 +128,41 @@ public static void mapCustomerToRequest(@Nonnull final AuthorizationRequest requ
});
}

public static void mapShippingAddressToRequest(final AuthorizationRequest request, final Address shippingAddress) {

if(shippingAddress == null) {
public static void mapShippingAddressToRequest(final AuthorizationRequest request,
final Address shippingAddress,
final String paymentMethod) {

if(shippingAddress != null) {
request.setShipping_firstname(shippingAddress.getFirstName());
request.setShipping_lastname(shippingAddress.getLastName());
request.setShipping_street(joinStringsIgnoringNull(Arrays.asList(shippingAddress.getStreetName(),
shippingAddress.getStreetNumber())));
request.setShipping_zip(shippingAddress.getPostalCode());
request.setShipping_city(shippingAddress.getCity());
request.setShipping_country(shippingAddress.getCountry().toLocale().getCountry());
request.setShipping_company(joinStringsIgnoringNull(Arrays.asList(shippingAddress.getCompany(),
shippingAddress.getDepartment())));

if (countriesWithStateAllowed.contains(shippingAddress.getCountry())) {
request.setShipping_state(shippingAddress.getState());
}
} else if(!MethodKeys.WALLET_PAYPAL.equals(paymentMethod)) {
throw new IllegalArgumentException("Missing shipping address details");
butenkor marked this conversation as resolved.
Show resolved Hide resolved
}
}

public static int checkForMissingShippingAddress(Address shippingAddress) {

request.setShipping_firstname(shippingAddress.getFirstName());
request.setShipping_lastname(shippingAddress.getLastName());
request.setShipping_street(joinStringsIgnoringNull(Arrays.asList(shippingAddress.getStreetName(),
shippingAddress.getStreetNumber())));
request.setShipping_zip(shippingAddress.getPostalCode());
request.setShipping_city(shippingAddress.getCity());
request.setShipping_country(shippingAddress.getCountry().toLocale().getCountry());
request.setShipping_company(joinStringsIgnoringNull(Arrays.asList(shippingAddress.getCompany(),
shippingAddress.getDepartment())));

if (countriesWithStateAllowed.contains(shippingAddress.getCountry())) {
request.setShipping_state(shippingAddress.getState());
if(shippingAddress == null
|| StringUtils.isBlank(shippingAddress.getPostalCode())
|| StringUtils.isBlank(shippingAddress.getCity())
|| StringUtils.isBlank(shippingAddress.getCountry().toLocale().getCountry())
|| StringUtils.isBlank(joinStringsIgnoringNull(asList(shippingAddress.getStreetName(),
shippingAddress.getStreetNumber())))
) {
return 1;
}
return 0;
}

public static void mapCustomFieldsFromPayment(final AuthorizationRequest request, final CustomFields ctPaymentCustomFields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ protected void mapFormPaymentWithCartLike(final AuthorizationRequest request,
}

try {
MappingUtil.mapShippingAddressToRequest(request, ctCartLike.getShippingAddress());
MappingUtil.mapShippingAddressToRequest(request, ctCartLike.getShippingAddress(),
ctPayment.getPaymentMethodInfo().getMethod());
} catch (final IllegalArgumentException ex) {
logger.debug(
createTenantKeyValue(tenantConfig.getName()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.commercetools.pspadapter.payone.domain.payone.model.wallet.WalletAuthorizationRequest;
import com.commercetools.pspadapter.payone.domain.payone.model.wallet.WalletPreauthorizationRequest;
import com.commercetools.pspadapter.tenant.TenantConfig;
import com.commercetools.util.function.TriFunction;
import io.sphere.sdk.carts.CartLike;
import io.sphere.sdk.payments.Payment;
import io.sphere.sdk.payments.PaymentMethodInfo;

Expand All @@ -16,7 +18,8 @@
/**
* Requests factory for Wallet based payments, like <i>PayPal</i> and <i>Paydirekt</i>.
* <p>Based on {@link PaymentMethodInfo#getMethod() Payment#paymentMethodInfo#method} value the request will be created
* with respective {@link WalletAuthorizationRequest#clearingtype} and {@link WalletAuthorizationRequest#wallettype}</p>
* with respective {@link WalletAuthorizationRequest#clearingtype}, {@link WalletAuthorizationRequest#wallettype}
* and {@link WalletAuthorizationRequest#noShipping}</p>
*/
public class WalletRequestFactory extends PayoneRequestFactory {

Expand All @@ -38,16 +41,18 @@ public WalletAuthorizationRequest createAuthorizationRequest(@Nonnull final Paym

@Nonnull
private <WR extends AuthorizationRequest> WR createRequestInternal(@Nonnull final PaymentWithCartLike paymentWithCartLike,
@Nonnull final BiFunction<? super PayoneConfig, ClearingType, WR> requestConstructor) {
@Nonnull final TriFunction<? super PayoneConfig, ClearingType, Integer, WR> requestConstructor) {

final Payment ctPayment = paymentWithCartLike.getPayment();
final CartLike ctCartLike = paymentWithCartLike.getCartLike();

if(ctPayment.getCustom() == null) {
throw new IllegalArgumentException("Missing custom fields on payment!");
}

final int noShippingAddress = MappingUtil.checkForMissingShippingAddress(ctCartLike.getShippingAddress());
final ClearingType clearingType = ClearingType.getClearingTypeByKey(ctPayment.getPaymentMethodInfo().getMethod());
WR request = requestConstructor.apply(getPayoneConfig(), clearingType);
WR request = requestConstructor.apply(getPayoneConfig(), clearingType, noShippingAddress);

mapFormPaymentWithCartLike(request, paymentWithCartLike);

Expand Down

This file was deleted.

Loading