diff --git a/src/main/java/io/paymenthighway/formBuilders/FormBuilderConstants.java b/src/main/java/io/paymenthighway/formBuilders/FormBuilderConstants.java index d690f06..2a18e36 100644 --- a/src/main/java/io/paymenthighway/formBuilders/FormBuilderConstants.java +++ b/src/main/java/io/paymenthighway/formBuilders/FormBuilderConstants.java @@ -26,6 +26,7 @@ public final class FormBuilderConstants { public final static String SPH_MOBILEPAY_PHONE_NUMBER = "sph-mobilepay-phone-number"; public final static String SPH_MOBILEPAY_SHOP_NAME = "sph-mobilepay-shop-name"; public final static String SPH_SUB_MERCHANT_ID = "sph-sub-merchant-id"; + public final static String SPH_SUB_MERCHANT_VAT_ID = "sph-sub-merchant-vat-id"; public final static String SPH_SUB_MERCHANT_MCC = "sph-sub-merchant-merchant-category-code"; public final static String SPH_SUB_MERCHANT_NAME = "sph-sub-merchant-name"; public final static String SPH_SUB_MERCHANT_STREET_ADDRESS = "sph-sub-merchant-street-address"; diff --git a/src/main/java/io/paymenthighway/formBuilders/GenericFormBuilder.java b/src/main/java/io/paymenthighway/formBuilders/GenericFormBuilder.java index cada586..37e9913 100644 --- a/src/main/java/io/paymenthighway/formBuilders/GenericFormBuilder.java +++ b/src/main/java/io/paymenthighway/formBuilders/GenericFormBuilder.java @@ -164,6 +164,10 @@ public T subMerchant(SubMerchant subMerchant) { addOrReplaceNameValuePair(FormBuilderConstants.SPH_SUB_MERCHANT_ID, subMerchant.getId()); addNameValuePair(FormBuilderConstants.SPH_SUB_MERCHANT_MCC, subMerchant.getMerchantCategoryCode()); + if (subMerchant.getVatId() != null) { + addNameValuePair(FormBuilderConstants.SPH_SUB_MERCHANT_VAT_ID, subMerchant.getVatId()); + } + addOrReplaceNameValuePair(FormBuilderConstants.SPH_SUB_MERCHANT_NAME, contactInformation.getName()); addNameValuePair(FormBuilderConstants.SPH_SUB_MERCHANT_STREET_ADDRESS, contactInformation.getStreetAddress()); addNameValuePair(FormBuilderConstants.SPH_SUB_MERCHANT_CITY, contactInformation.getCity()); diff --git a/src/main/java/io/paymenthighway/model/request/SubMerchant.java b/src/main/java/io/paymenthighway/model/request/SubMerchant.java index dd4ab44..44a0c20 100644 --- a/src/main/java/io/paymenthighway/model/request/SubMerchant.java +++ b/src/main/java/io/paymenthighway/model/request/SubMerchant.java @@ -9,6 +9,8 @@ public class SubMerchant { String merchantCategoryCode; @JsonProperty("contact_information") ContactInformation contactInformation; + @JsonProperty("vat_id") + String vatId; /** * Sub-merchant details, only to be used if initiated by a Payment Facilitator @@ -22,6 +24,20 @@ public SubMerchant(String id, String merchantCategoryCode, ContactInformation co this.contactInformation = contactInformation; } + /** + * Sub-merchant details, only to be used if initiated by a Payment Facilitator + * @param id Payment Facilitator assigned numeric sub-merchant identifier + * @param merchantCategoryCode Four digit merchant category code + * @param contactInformation Sub-merchant's contact details + * @param vatId Sub-merchant's VAT ID, required for MobilePay requests + */ + public SubMerchant(String id, String merchantCategoryCode, ContactInformation contactInformation, String vatId) { + this.id = id; + this.merchantCategoryCode = merchantCategoryCode; + this.contactInformation = contactInformation; + this.vatId = vatId; + } + public String getId() { return id; } @@ -33,4 +49,8 @@ public String getMerchantCategoryCode() { public ContactInformation getContactInformation() { return contactInformation; } + + public String getVatId() { + return vatId; + } } diff --git a/src/test/java/io/paymenthighway/FormBuilderTest.java b/src/test/java/io/paymenthighway/FormBuilderTest.java index 7d65b69..a06719a 100644 --- a/src/test/java/io/paymenthighway/FormBuilderTest.java +++ b/src/test/java/io/paymenthighway/FormBuilderTest.java @@ -804,14 +804,15 @@ public void testMobilePaySplittingAndSubMerchant() { FormBuilder formBuilder = createFormBuilder(method, account, merchant); + SubMerchant testSubMerchantWithVatId = TestResources.TestSubMerchantWithVatId; FormContainer formContainer = formBuilder.mobilePayParametersBuilder(successUrl, failureUrl, cancelUrl, amount, currency, orderId, description) .splitting(splittingMerchantId, splittingAmount) - .subMerchant(TestResources.TestSubMerchant) + .subMerchant(testSubMerchantWithVatId) .build(); - assertEquals(23, formContainer.getFields().size()); + assertEquals(24, formContainer.getFields().size()); checkSplittingParameters(formContainer.getFields(), splittingMerchantIdString, splittingAmountString); - checkSubMerchantParameters(formContainer.getFields(), TestResources.TestSubMerchant); + checkSubMerchantWithVatIdParameters(formContainer.getFields(), testSubMerchantWithVatId); } @Test @@ -956,4 +957,9 @@ private void checkSubMerchantParameters(List parameterList, SubMe Helper.assertFieldValueExists(parameterList, FormBuilderConstants.SPH_SUB_MERCHANT_TELEPHONE, contactInformation.getTelephone()); Helper.assertFieldValueExists(parameterList, FormBuilderConstants.SPH_SUB_MERCHANT_COUNTRY_CODE, contactInformation.getCountryCode()); } + + private void checkSubMerchantWithVatIdParameters(List parameterList, SubMerchant subMerchant) { + checkSubMerchantParameters(parameterList, subMerchant); + Helper.assertFieldValueExists(parameterList, FormBuilderConstants.SPH_SUB_MERCHANT_VAT_ID, subMerchant.getVatId()); + } } diff --git a/src/test/java/io/paymenthighway/model/request/MobilePayInitRequestTest.java b/src/test/java/io/paymenthighway/model/request/MobilePayInitRequestTest.java index facb8db..2bfaa48 100644 --- a/src/test/java/io/paymenthighway/model/request/MobilePayInitRequestTest.java +++ b/src/test/java/io/paymenthighway/model/request/MobilePayInitRequestTest.java @@ -12,11 +12,13 @@ public class MobilePayInitRequestTest { @Test public void serializeUriAndUrls() throws Exception { + SubMerchant testSubMerchant = TestResources.TestSubMerchantWithVatId; + MobilePayInitRequest request = MobilePayInitRequest.Builder(1000, "EUR") .setWebhookSuccessUrl(new URL("https://myapp.server/success")) .setWebhookCancelUrl("https://myapp.server/cancel") .setReturnUri(new URI("myapp://view")) - .setSubMerchant(TestResources.TestSubMerchant) + .setSubMerchant(testSubMerchant) .build(); JsonGenerator jsonGenerator = new JsonGenerator(); @@ -26,6 +28,6 @@ public void serializeUriAndUrls() throws Exception { assertTrue(json.contains("https://myapp.server/cancel")); assertTrue(json.contains("myapp://view")); - TestResources.assertTestSubMerchant(json); + TestResources.assertTestSubMerchantWithVatId(json, testSubMerchant); } } diff --git a/src/test/java/io/paymenthighway/model/request/PaymentRequestBuilderTest.java b/src/test/java/io/paymenthighway/model/request/PaymentRequestBuilderTest.java index 439103e..648b43e 100644 --- a/src/test/java/io/paymenthighway/model/request/PaymentRequestBuilderTest.java +++ b/src/test/java/io/paymenthighway/model/request/PaymentRequestBuilderTest.java @@ -8,6 +8,8 @@ public class PaymentRequestBuilderTest { @Test public void testPivoRequestBuilder() throws Exception { + SubMerchant testSubMerchant = TestResources.TestSubMerchant; + PivoInitRequest request = PivoInitRequest.Builder(1L, "EUR") .setWebhookCancelUrl("http://www.example.com/cancel") .setWebhookFailureUrl("http://www.example.com/failure") @@ -16,7 +18,7 @@ public void testPivoRequestBuilder() throws Exception { .setAppUrl("app://url") .setOrder("orderNumber") .setDescription("simple description") - .setSubMerchant(TestResources.TestSubMerchant) + .setSubMerchant(testSubMerchant) .build(); JsonGenerator jsonGenerator = new JsonGenerator(); @@ -31,6 +33,6 @@ public void testPivoRequestBuilder() throws Exception { JsonTestHelper.testJson(json, "order", "orderNumber"); JsonTestHelper.testJson(json, "description", "simple description"); - TestResources.assertTestSubMerchant(json); + TestResources.assertTestSubMerchant(json, testSubMerchant); } } diff --git a/src/test/java/io/paymenthighway/model/request/TransactionRequestTest.java b/src/test/java/io/paymenthighway/model/request/TransactionRequestTest.java index 0bde247..dd6dfc1 100644 --- a/src/test/java/io/paymenthighway/model/request/TransactionRequestTest.java +++ b/src/test/java/io/paymenthighway/model/request/TransactionRequestTest.java @@ -74,14 +74,16 @@ public void citRequestBuildsWithSubMerchant() { ).build()).build(); + SubMerchant testSubMerchant = TestResources.TestSubMerchant; + ChargeCitRequest request = ChargeCitRequest .Builder(token, 99L, "EUR", orderId, sca) - .setSubMerchant(TestResources.TestSubMerchant) + .setSubMerchant(testSubMerchant) .build(); String json = new JsonGenerator().createTransactionJson(request); - TestResources.assertTestSubMerchant(json); + TestResources.assertTestSubMerchant(json, testSubMerchant); } @Test @@ -90,13 +92,15 @@ public void mitRequestBuildsWithSubMerchant() { String orderId = "order_123"; + SubMerchant testSubMerchant = TestResources.TestSubMerchant; + ChargeMitRequest request = ChargeMitRequest .Builder(token, 99L, "EUR", orderId) - .setSubMerchant(TestResources.TestSubMerchant) + .setSubMerchant(testSubMerchant) .build(); String json = new JsonGenerator().createTransactionJson(request); - TestResources.assertTestSubMerchant(json); + TestResources.assertTestSubMerchant(json, testSubMerchant); } } diff --git a/src/test/java/io/paymenthighway/test/TestResources.java b/src/test/java/io/paymenthighway/test/TestResources.java index 4a6bfab..09b98c8 100644 --- a/src/test/java/io/paymenthighway/test/TestResources.java +++ b/src/test/java/io/paymenthighway/test/TestResources.java @@ -18,12 +18,26 @@ public class TestResources { ) ); - public static void assertTestSubMerchant(String json) { + public static SubMerchant TestSubMerchantWithVatId = new SubMerchant( + "123456789", + "8999", + new ContactInformation( + "Super Neat Service", + "Street 123", + "Helsinki", + "00100", + "FI", + "+3581231234" + ), + "987654321" + ); + + public static void assertTestSubMerchant(String json, SubMerchant testSubMerchant) { JsonTestHelper.keyExists(json, "sub_merchant"); - JsonTestHelper.testJson(json, "id", TestSubMerchant.getId()); - JsonTestHelper.testJson(json, "merchant_category_code", TestSubMerchant.getMerchantCategoryCode()); + JsonTestHelper.testJson(json, "id", testSubMerchant.getId()); + JsonTestHelper.testJson(json, "merchant_category_code", testSubMerchant.getMerchantCategoryCode()); - ContactInformation contactInformation = TestSubMerchant.getContactInformation(); + ContactInformation contactInformation = testSubMerchant.getContactInformation(); JsonTestHelper.keyExists(json, "contact_information"); JsonTestHelper.testJson(json, "name", contactInformation.getName()); @@ -33,4 +47,22 @@ public static void assertTestSubMerchant(String json) { JsonTestHelper.testJson(json, "country_code", contactInformation.getCountryCode()); JsonTestHelper.testJson(json, "telephone", contactInformation.getTelephone()); } + + public static void assertTestSubMerchantWithVatId(String json, SubMerchant testSubMerchant) { + JsonTestHelper.keyExists(json, "sub_merchant"); + JsonTestHelper.testJson(json, "id", testSubMerchant.getId()); + JsonTestHelper.testJson(json, "merchant_category_code", testSubMerchant.getMerchantCategoryCode()); + + ContactInformation contactInformation = testSubMerchant.getContactInformation(); + + JsonTestHelper.keyExists(json, "contact_information"); + JsonTestHelper.testJson(json, "name", contactInformation.getName()); + JsonTestHelper.testJson(json, "street_address", contactInformation.getStreetAddress()); + JsonTestHelper.testJson(json, "city", contactInformation.getCity()); + JsonTestHelper.testJson(json, "postal_code", contactInformation.getPostalCode()); + JsonTestHelper.testJson(json, "country_code", contactInformation.getCountryCode()); + JsonTestHelper.testJson(json, "telephone", contactInformation.getTelephone()); + + JsonTestHelper.testJson(json, "vat_id", testSubMerchant.getVatId()); + } }