-
Notifications
You must be signed in to change notification settings - Fork 2
CC-2019/add-basket-v3 #171
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b357b14
[CC-2018] Add customer v2.
Ryouzanpaku 69ae5a4
[CC-2018] Add customer v2.
Ryouzanpaku 902add4
[CC-2019] Add basket v3.
Ryouzanpaku ad7cb7f
[CC-2019] Merge branch 'main' into CC-2019/add-basket-v3
Ryouzanpaku 27dfe08
[CC-2019] [CC-2019] cleanup redundant tests
Ryouzanpaku 21e20df
[CC-2019] Merge remote-tracking branch 'refs/remotes/origin/main' int…
Ryouzanpaku 07628a2
[CC-2019] Fix authentication for new resources.
Ryouzanpaku 1364b9e
[CC-2019] Fix Review comments.
Ryouzanpaku File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.unzer.payment; | ||
|
|
||
| public class BasketV3 extends Basket { | ||
| @Override | ||
| protected String getResourceUrl() { | ||
| return "/v3/baskets/<resourceId>"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/test/java/com/unzer/payment/business/BasketV3Test.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package com.unzer.payment.business; | ||
|
|
||
| import com.unzer.payment.Basket; | ||
| import com.unzer.payment.Charge; | ||
| import com.unzer.payment.Payment; | ||
| import com.unzer.payment.integration.resources.BearerAuthBaseTest; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| import static com.unzer.payment.business.BasketV3TestData.getMaxTestBasketV3; | ||
| import static com.unzer.payment.business.BasketV3TestData.getMinTestBasketV3; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
|
||
| class BasketV3Test extends BearerAuthBaseTest { | ||
| @Test | ||
| void testCreateFetchBasket() { | ||
| Basket maxBasket = getMaxTestBasketV3(); | ||
| Basket basket = getUnzer().createBasket(maxBasket); | ||
|
|
||
| // when | ||
| Basket basketFetched = getUnzer().fetchBasket(basket.getId()); | ||
|
|
||
| // then | ||
| assertNotNull(basketFetched); | ||
| assertNotNull(basketFetched.getId()); | ||
| assertBasketEquals(maxBasket, basketFetched); | ||
| } | ||
|
|
||
| @Test | ||
| void testCreateFetchMinBasket() { | ||
| Basket minBasket = getMinTestBasketV3(); | ||
| Basket basket = getUnzer().createBasket(minBasket); | ||
|
|
||
| // when | ||
| Basket basketFetched = getUnzer().fetchBasket(basket.getId()); | ||
|
|
||
| // then | ||
| assertBasketEquals(minBasket, basketFetched); | ||
| } | ||
|
|
||
| @Test | ||
| void testUpdateBasket() { | ||
| Basket minBasket = getMinTestBasketV3(); | ||
| Basket basket = getUnzer().createBasket(minBasket); | ||
| Basket maxBasket = getMaxTestBasketV3(); | ||
| maxBasket.setOrderId(basket.getOrderId()); | ||
|
|
||
| // when | ||
| Basket updatedBasket = getUnzer().updateBasket(maxBasket, basket.getId()); | ||
|
|
||
| //then | ||
| assertBasketEquals(maxBasket, updatedBasket); | ||
| } | ||
|
|
||
| @Test | ||
| void testChargeWithBasket() { | ||
| Basket basket = getUnzer().createBasket(getMaxTestBasketV3()); | ||
| Charge chargeReq = | ||
| getCharge(createPaymentTypeCard(getUnzer(), "4711100000000000").getId(), null, null, null, | ||
| basket.getId(), null); | ||
| chargeReq.setAmount(BigDecimal.valueOf(684.47)); | ||
| Charge charge = getUnzer().charge(chargeReq); | ||
|
|
||
| //when | ||
| Payment payment = getUnzer().fetchPayment(charge.getPayment().getId()); | ||
|
|
||
| //then | ||
| assertNotNull(payment); | ||
| assertNotNull(payment.getId()); | ||
| assertNotNull(payment.getCharge(0)); | ||
| assertNotNull(payment.getCharge(0).getId()); | ||
| assertEquals(basket.getId(), payment.getBasketId()); | ||
| assertEquals(basket.getId(), payment.getCharge(0).getBasketId()); | ||
| } | ||
|
|
||
| private void assertBasketEquals(Basket expected, Basket actual) { | ||
| assertThat(expected) | ||
| .usingComparatorForType(BigDecimal::compareTo, BigDecimal.class) | ||
| .usingRecursiveComparison() | ||
| .isEqualTo(actual); | ||
| } | ||
| } | ||
79 changes: 79 additions & 0 deletions
79
src/test/java/com/unzer/payment/business/BasketV3TestData.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package com.unzer.payment.business; | ||
|
|
||
| import com.unzer.payment.Basket; | ||
| import com.unzer.payment.BasketItem; | ||
| import com.unzer.payment.BasketV3; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.Currency; | ||
|
|
||
| import static com.unzer.payment.util.Types.unsafeUrl; | ||
| import static com.unzer.payment.util.Uuid.generateUuid; | ||
|
|
||
| public class BasketV3TestData { | ||
| public static Basket getMaxTestBasketV3() { | ||
| return new BasketV3() | ||
| .setTotalValueGross(new BigDecimal("380.48")) | ||
| .setCurrencyCode(Currency.getInstance("EUR")) | ||
| .setOrderId(generateUuid()) | ||
| .addBasketItem(getMaxTestBasketItem1V2()) // 14.48 - 1.0 | ||
| .addBasketItem(getMaxTestBasketItem2V2()); // 366 // 122 * 3 | ||
| } | ||
|
|
||
| public static BasketItem getMaxTestBasketItem2V2() { | ||
| return new BasketItem() | ||
| .setBasketItemReferenceId("Artikelnummer4712") | ||
| .setAmountPerUnitGross(new BigDecimal("122")) | ||
| .setQuantity(3) | ||
| .setTitle("Apple iPad Air") | ||
| .setUnit("Pc.") | ||
| .setAmountDiscountPerUnitGross(BigDecimal.ZERO) | ||
| .setVat(BigDecimal.valueOf(20)) | ||
| .setSubTitle("Nicht nur Pros brauchen Power.") | ||
| .setType(BasketItem.Type.GOODS) | ||
| .setImageUrl(unsafeUrl("https://store.storeimages.cdn-apple.com/4668/as-images.apple.com/is/iphone-12-pro-family-hero")); | ||
| } | ||
|
|
||
|
|
||
| public static BasketItem getMaxTestBasketItem1V2() { | ||
| return new BasketItem() | ||
| .setBasketItemReferenceId("Artikelnummer4711") | ||
| .setAmountPerUnitGross(new BigDecimal("24.48")) | ||
| .setAmountDiscountPerUnitGross(BigDecimal.TEN) | ||
| .setQuantity(1) | ||
| .setTitle("Apple iPhone") | ||
| .setUnit("Pc.") | ||
| .setVat(BigDecimal.valueOf(19)) | ||
| .setSubTitle("XS in Red").setType(BasketItem.Type.GOODS) | ||
| .setImageUrl(unsafeUrl("https://store.storeimages.cdn-apple.com/4668/as-images.apple.com/is/iphone-12-pro-family-hero")); | ||
| } | ||
|
|
||
| public static Basket getMaxTestBasketV3(BigDecimal amount) { | ||
| return new BasketV3() | ||
| .setTotalValueGross(amount) | ||
| .setCurrencyCode(Currency.getInstance("EUR")) | ||
| .setOrderId(generateUuid()) | ||
| .addBasketItem(getMaxTestBasketItem1V2()) | ||
| .addBasketItem(getMaxTestBasketItem2V2()); | ||
| } | ||
|
|
||
|
|
||
| public static BasketItem getMinTestBasketItemV2() { | ||
| return new BasketItem() | ||
| .setBasketItemReferenceId("Artikelnummer4711") | ||
| .setQuantity(5) | ||
| .setVat(BigDecimal.ZERO) | ||
| .setAmountDiscountPerUnitGross(BigDecimal.ZERO) | ||
| .setAmountPerUnitGross(new BigDecimal("100.1")) | ||
| .setTitle("Apple iPhone"); | ||
| } | ||
|
|
||
|
|
||
| public static Basket getMinTestBasketV3() { | ||
| return new BasketV3() | ||
| .setTotalValueGross(new BigDecimal("500.5")) | ||
| .setCurrencyCode(Currency.getInstance("EUR")) | ||
| .setOrderId(generateUuid()) | ||
| .addBasketItem(getMinTestBasketItemV2()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.