Skip to content

Commit

Permalink
Merge branch 'release/2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankazokas committed Feb 24, 2021
2 parents aa1b1ae + 87c84e7 commit 2229ac3
Show file tree
Hide file tree
Showing 8 changed files with 1,365 additions and 1,308 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.channelape</groupId>
<artifactId>shopify-sdk</artifactId>
<version>2.1.0</version>
<version>2.2.0</version>

<name>Shopify SDK</name>
<description>Java SDK for Shopify REST API.</description>
Expand Down
81 changes: 81 additions & 0 deletions src/main/java/com/shopify/model/ShopifyAdjustment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.shopify.model;

import java.math.BigDecimal;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ShopifyAdjustment {

private String id;
@XmlElement(name = "order_id")
private String orderId;
@XmlElement(name = "refund_id")
private String refundId;
private BigDecimal amount;
@XmlElement(name = "tax_amount")
private BigDecimal taxAmount;
private String kind;
private String reason;

public String getId() {
return id;
}

public void setId(final String id) {
this.id = id;
}

public String getOrderId() {
return orderId;
}

public void setOrderId(final String orderId) {
this.orderId = orderId;
}

public String getRefundId() {
return refundId;
}

public void setRefundId(final String refundId) {
this.refundId = refundId;
}

public BigDecimal getAmount() {
return amount;
}

public void setAmount(final BigDecimal amount) {
this.amount = amount;
}

public BigDecimal getTaxAmount() {
return taxAmount;
}

public void setTaxAmount(final BigDecimal taxAmount) {
this.taxAmount = taxAmount;
}

public String getKind() {
return kind;
}

public void setKind(final String kind) {
this.kind = kind;
}

public String getReason() {
return reason;
}

public void setReason(final String reason) {
this.reason = reason;
}

}
20 changes: 20 additions & 0 deletions src/main/java/com/shopify/model/ShopifyAdjustmentsRoot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.shopify.model;

import java.util.LinkedList;
import java.util.List;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class ShopifyAdjustmentsRoot {

private List<ShopifyAdjustment> adjustments = new LinkedList<>();

public List<ShopifyAdjustment> getAdjustments() {
return adjustments;
}

public void setAdjustments(final List<ShopifyAdjustment> adjustments) {
this.adjustments = adjustments;
}
}
13 changes: 12 additions & 1 deletion src/main/java/com/shopify/model/ShopifyRefund.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shopify.model;

import java.util.Currency;
import java.util.LinkedList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
Expand Down Expand Up @@ -33,7 +34,9 @@ public class ShopifyRefund {
@XmlElement(name = "refund_line_items")
private List<ShopifyRefundLineItem> refundLineItems;
private ShopifyRefundShippingDetails shipping;
private List<ShopifyTransaction> transactions;
private List<ShopifyTransaction> transactions = new LinkedList<>();
@XmlElement(name = "order_adjustments")
private List<ShopifyAdjustment> adjustments = new LinkedList<>();
@XmlJavaTypeAdapter(CurrencyAdapter.class)
private Currency currency;

Expand Down Expand Up @@ -109,6 +112,14 @@ public void setTransactions(final List<ShopifyTransaction> transactions) {
this.transactions = transactions;
}

public List<ShopifyAdjustment> getAdjustments() {
return adjustments;
}

public void setAdjustments(final List<ShopifyAdjustment> adjustments) {
this.adjustments = adjustments;
}

public Currency getCurrency() {
return currency;
}
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/shopify/model/ShopifyTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,30 @@
@XmlAccessorType(XmlAccessType.FIELD)
public class ShopifyTransaction {

private String id;
@XmlElement(name = "order_id")
private String orderId;
private String kind;
private String gateway;
@XmlElement(name = "parent_id")
private String parentId;
private String status;
private String message;
private BigDecimal amount;
@XmlJavaTypeAdapter(CurrencyAdapter.class)
private Currency currency;
@XmlElement(name = "maximum_refundable")
private BigDecimal maximumRefundable;
private ShopifyTransactionReceipt receipt;

public String getId() {
return id;
}

public void setId(final String id) {
this.id = id;
}

public String getOrderId() {
return orderId;
}
Expand Down Expand Up @@ -60,6 +71,22 @@ public void setParentId(final String parentId) {
this.parentId = parentId;
}

public String getStatus() {
return status;
}

public void setStatus(final String status) {
this.status = status;
}

public String getMessage() {
return message;
}

public void setMessage(final String message) {
this.message = message;
}

public BigDecimal getAmount() {
return amount;
}
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/com/shopify/ShopifySdkDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.Currency;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
Expand Down Expand Up @@ -203,6 +204,39 @@ public void givenValidOrderIdWhenRetrievingOrderThenReturnShopifyOrder() {
actualShopifyOrder.getLineItems().get(1).getTaxLines().get(0).getTitle());
}

@Test
public void givenValidOrderIdWithRefundTransactionsAndAdjustmentAndNoRefundLineItemsWhenRetrievingOrderThenReturnShopifyOrder() {
final String orderId = "2934166880317";

final ShopifyOrder actualShopifyOrder = shopifySdk.getOrder(orderId);

assertEquals("humding-6593", actualShopifyOrder.getName());
assertEquals(1, actualShopifyOrder.getRefunds().size());

assertEquals("702404231229", actualShopifyOrder.getRefunds().get(0).getId());

assertEquals(0, actualShopifyOrder.getRefunds().get(0).getRefundLineItems().size());

assertEquals("3714516516925", actualShopifyOrder.getRefunds().get(0).getTransactions().get(0).getId());
assertEquals("3621807685693", actualShopifyOrder.getRefunds().get(0).getTransactions().get(0).getParentId());
assertEquals(Currency.getInstance("USD"),
actualShopifyOrder.getRefunds().get(0).getTransactions().get(0).getCurrency());
assertEquals("manual", actualShopifyOrder.getRefunds().get(0).getTransactions().get(0).getGateway());
assertEquals("refund", actualShopifyOrder.getRefunds().get(0).getTransactions().get(0).getKind());
assertTrue(BigDecimal.valueOf(25.00)
.compareTo(actualShopifyOrder.getRefunds().get(0).getTransactions().get(0).getAmount()) == 0);

assertEquals("130293006397", actualShopifyOrder.getRefunds().get(0).getAdjustments().get(0).getId());
assertEquals("702404231229", actualShopifyOrder.getRefunds().get(0).getAdjustments().get(0).getRefundId());
assertEquals("refund_discrepancy", actualShopifyOrder.getRefunds().get(0).getAdjustments().get(0).getKind());
assertEquals("Refund discrepancy", actualShopifyOrder.getRefunds().get(0).getAdjustments().get(0).getReason());
assertTrue(BigDecimal.valueOf(-25.00)
.compareTo(actualShopifyOrder.getRefunds().get(0).getAdjustments().get(0).getAmount()) == 0);
assertTrue(BigDecimal.valueOf(0.00)
.compareTo(actualShopifyOrder.getRefunds().get(0).getAdjustments().get(0).getTaxAmount()) == 0);

}

@Test
public void givenValidOrderIdWhenCancelingOrderThenCancelShopifyOrder() {
final String orderId = "5388977100";
Expand Down
85 changes: 85 additions & 0 deletions src/test/java/com/shopify/ShopifySdkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import com.shopify.model.Shop;
import com.shopify.model.ShopifyAccessTokenRoot;
import com.shopify.model.ShopifyAddress;
import com.shopify.model.ShopifyAdjustment;
import com.shopify.model.ShopifyAttribute;
import com.shopify.model.ShopifyCustomCollection;
import com.shopify.model.ShopifyCustomCollectionCreationRequest;
Expand Down Expand Up @@ -421,6 +422,39 @@ public void givenSomePageAndCreatedAtMinAndCreatedAtMaxOrdersWhenRetrievingOrder

shopifyRefund1.setRefundLineItems(Arrays.asList(shopifyRefundedLineItem));

final ShopifyTransaction shopifyTransaction1 = new ShopifyTransaction();
shopifyTransaction1.setId("123");
shopifyTransaction1.setMessage("Refunded 12.72 from manual gateway");
shopifyTransaction1.setAmount(new BigDecimal(12.72));
shopifyTransaction1.setStatus("SUCCESS");
shopifyTransaction1.setKind("refund_discrepancy");
shopifyTransaction1.setGateway("manual");
shopifyTransaction1.setCurrency(Currency.getInstance("USD"));
shopifyTransaction1.setMaximumRefundable(new BigDecimal(15.99));

final ShopifyTransaction shopifyTransaction2 = new ShopifyTransaction();
shopifyTransaction2.setId("456");
shopifyTransaction2.setAmount(new BigDecimal("10.50"));
shopifyTransaction2.setStatus("FAILURE");
shopifyTransaction2.setKind("refund_discrepancy");
shopifyTransaction2.setGateway("manual");
shopifyTransaction2.setCurrency(Currency.getInstance("USD"));
shopifyTransaction2.setMaximumRefundable(new BigDecimal(15.99));

shopifyRefund1.setTransactions(Arrays.asList(shopifyTransaction1, shopifyTransaction2));

final ShopifyAdjustment shopifyAdjustment1 = new ShopifyAdjustment();
shopifyAdjustment1.setId("1230");
shopifyAdjustment1.setAmount(new BigDecimal("-12.00"));
shopifyAdjustment1.setTaxAmount(new BigDecimal("-0.72"));
shopifyAdjustment1.setReason("Shipping Refund");

final ShopifyAdjustment shopifyAdjustment2 = new ShopifyAdjustment();
shopifyAdjustment2.setId("4560");
shopifyAdjustment2.setAmount(new BigDecimal("-10.00"));

shopifyRefund1.setAdjustments(Arrays.asList(shopifyAdjustment1, shopifyAdjustment2));

shopifyOrder1.setRefunds(Arrays.asList(shopifyRefund1));
shopifyOrdersRoot.setOrders(Arrays.asList(shopifyOrder1));

Expand Down Expand Up @@ -500,6 +534,57 @@ public void givenSomePageAndCreatedAtMinAndCreatedAtMaxOrdersWhenRetrievingOrder
assertEquals(shopifyOrder1.getRefunds().get(0).getRefundLineItems().get(0).getTotalTax(),
shopifyOrders.get(0).getRefunds().get(0).getRefundLineItems().get(0).getTotalTax());

assertEquals(shopifyOrder1.getRefunds().get(0).getTransactions().get(0).getId(),
shopifyOrders.get(0).getRefunds().get(0).getTransactions().get(0).getId());
assertEquals(shopifyOrder1.getRefunds().get(0).getTransactions().get(0).getAmount(),
shopifyOrders.get(0).getRefunds().get(0).getTransactions().get(0).getAmount());
assertEquals(shopifyOrder1.getRefunds().get(0).getTransactions().get(0).getMessage(),
shopifyOrders.get(0).getRefunds().get(0).getTransactions().get(0).getMessage());
assertEquals(shopifyOrder1.getRefunds().get(0).getTransactions().get(0).getStatus(),
shopifyOrders.get(0).getRefunds().get(0).getTransactions().get(0).getStatus());
assertEquals(shopifyOrder1.getRefunds().get(0).getTransactions().get(0).getKind(),
shopifyOrders.get(0).getRefunds().get(0).getTransactions().get(0).getKind());
assertEquals(shopifyOrder1.getRefunds().get(0).getTransactions().get(0).getGateway(),
shopifyOrders.get(0).getRefunds().get(0).getTransactions().get(0).getGateway());
assertEquals(shopifyOrder1.getRefunds().get(0).getTransactions().get(0).getCurrency(),
shopifyOrders.get(0).getRefunds().get(0).getTransactions().get(0).getCurrency());
assertEquals(shopifyOrder1.getRefunds().get(0).getTransactions().get(0).getMaximumRefundable(),
shopifyOrders.get(0).getRefunds().get(0).getTransactions().get(0).getMaximumRefundable());

assertEquals(shopifyOrder1.getRefunds().get(0).getTransactions().get(1).getId(),
shopifyOrders.get(0).getRefunds().get(0).getTransactions().get(1).getId());
assertEquals(shopifyOrder1.getRefunds().get(0).getTransactions().get(1).getAmount(),
shopifyOrders.get(0).getRefunds().get(0).getTransactions().get(1).getAmount());
assertEquals(shopifyOrder1.getRefunds().get(0).getTransactions().get(1).getMessage(),
shopifyOrders.get(0).getRefunds().get(0).getTransactions().get(1).getMessage());
assertEquals(shopifyOrder1.getRefunds().get(0).getTransactions().get(1).getStatus(),
shopifyOrders.get(0).getRefunds().get(0).getTransactions().get(1).getStatus());
assertEquals(shopifyOrder1.getRefunds().get(0).getTransactions().get(1).getKind(),
shopifyOrders.get(0).getRefunds().get(0).getTransactions().get(1).getKind());
assertEquals(shopifyOrder1.getRefunds().get(0).getTransactions().get(1).getGateway(),
shopifyOrders.get(0).getRefunds().get(0).getTransactions().get(1).getGateway());
assertEquals(shopifyOrder1.getRefunds().get(0).getTransactions().get(1).getCurrency(),
shopifyOrders.get(0).getRefunds().get(0).getTransactions().get(1).getCurrency());
assertEquals(shopifyOrder1.getRefunds().get(0).getTransactions().get(1).getMaximumRefundable(),
shopifyOrders.get(0).getRefunds().get(0).getTransactions().get(1).getMaximumRefundable());

assertEquals(shopifyOrder1.getRefunds().get(0).getAdjustments().get(0).getId(),
shopifyOrders.get(0).getRefunds().get(0).getAdjustments().get(0).getId());
assertEquals(shopifyOrder1.getRefunds().get(0).getAdjustments().get(0).getAmount(),
shopifyOrders.get(0).getRefunds().get(0).getAdjustments().get(0).getAmount());
assertEquals(shopifyOrder1.getRefunds().get(0).getAdjustments().get(0).getTaxAmount(),
shopifyOrders.get(0).getRefunds().get(0).getAdjustments().get(0).getTaxAmount());
assertEquals(shopifyOrder1.getRefunds().get(0).getAdjustments().get(0).getReason(),
shopifyOrders.get(0).getRefunds().get(0).getAdjustments().get(0).getReason());
assertEquals(shopifyOrder1.getRefunds().get(0).getAdjustments().get(1).getId(),
shopifyOrders.get(0).getRefunds().get(0).getAdjustments().get(1).getId());
assertEquals(shopifyOrder1.getRefunds().get(0).getAdjustments().get(1).getAmount(),
shopifyOrders.get(0).getRefunds().get(0).getAdjustments().get(1).getAmount());
assertEquals(shopifyOrder1.getRefunds().get(0).getAdjustments().get(1).getTaxAmount(),
shopifyOrders.get(0).getRefunds().get(0).getAdjustments().get(1).getTaxAmount());
assertEquals(shopifyOrder1.getRefunds().get(0).getAdjustments().get(1).getReason(),
shopifyOrders.get(0).getRefunds().get(0).getAdjustments().get(1).getReason());

assertEquals(shopifyLineItem1.getSku(),
shopifyOrders.get(0).getRefunds().get(0).getRefundLineItems().get(0).getLineItem().getSku());
assertEquals("456", shopifyOrders.getNextPageInfo());
Expand Down
Loading

0 comments on commit 2229ac3

Please sign in to comment.