Skip to content

Commit

Permalink
Merge pull request #75 from harpernexi/add-vat-id-to-submerchant
Browse files Browse the repository at this point in the history
Add VAT ID field to SubMerchant and in Form API constants
  • Loading branch information
harpernexi authored Nov 14, 2023
2 parents 96bde2c + 9d87c1c commit 5b73843
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/io/paymenthighway/model/request/SubMerchant.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand All @@ -33,4 +49,8 @@ public String getMerchantCategoryCode() {
public ContactInformation getContactInformation() {
return contactInformation;
}

public String getVatId() {
return vatId;
}
}
12 changes: 9 additions & 3 deletions src/test/java/io/paymenthighway/FormBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -956,4 +957,9 @@ private void checkSubMerchantParameters(List<NameValuePair> 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<NameValuePair> parameterList, SubMerchant subMerchant) {
checkSubMerchantParameters(parameterList, subMerchant);
Helper.assertFieldValueExists(parameterList, FormBuilderConstants.SPH_SUB_MERCHANT_VAT_ID, subMerchant.getVatId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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();
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
40 changes: 36 additions & 4 deletions src/test/java/io/paymenthighway/test/TestResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
}
}

0 comments on commit 5b73843

Please sign in to comment.