forked from getconversio/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add endpoint for Shopify Payments transactions && Order Risk (#254)
- Loading branch information
1 parent
e40406f
commit 6898174
Showing
9 changed files
with
996 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,14 @@ | ||
{ | ||
"risk": { | ||
"id": 284138680, | ||
"order_id": 450789469, | ||
"checkout_id": 0, | ||
"source": "External", | ||
"score": "1.0", | ||
"recommendation": "cancel", | ||
"display": true, | ||
"cause_cancel": true, | ||
"message": "This order was placed from a proxy IP", | ||
"merchant_message": "This order was placed from a proxy IP" | ||
} | ||
} |
This file contains 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,28 @@ | ||
{ | ||
"risks": [ | ||
{ | ||
"id": 284138680, | ||
"order_id": 450789469, | ||
"checkout_id": 0, | ||
"source": "External", | ||
"score": "1.0", | ||
"recommendation": "cancel", | ||
"display": true, | ||
"cause_cancel": true, | ||
"message": "This order was placed from a proxy IP", | ||
"merchant_message": "This order was placed from a proxy IP" | ||
}, | ||
{ | ||
"id": 1029151489, | ||
"order_id": 450789469, | ||
"checkout_id": 901414060, | ||
"source": "External", | ||
"score": "1.0", | ||
"recommendation": "cancel", | ||
"display": true, | ||
"cause_cancel": true, | ||
"message": "This order came from an anonymous proxy", | ||
"merchant_message": "This order came from an anonymous proxy" | ||
} | ||
] | ||
} |
This file contains 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,18 @@ | ||
{ | ||
"transaction": { | ||
"id": 699519475, | ||
"type": "debit", | ||
"test": false, | ||
"payout_id": 623721858, | ||
"payout_status": "paid", | ||
"currency": "USD", | ||
"amount": "-50.00", | ||
"fee": "0.00", | ||
"net": "-50.00", | ||
"source_id": 460709370, | ||
"source_type": "adjustment", | ||
"source_order_id": 0, | ||
"source_order_transaction_id": 0, | ||
"processed_at": "2013-11-01" | ||
} | ||
} |
This file contains 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,52 @@ | ||
{ | ||
"transactions": [ | ||
{ | ||
"id": 699519475, | ||
"type": "debit", | ||
"test": false, | ||
"payout_id": 623721858, | ||
"payout_status": "paid", | ||
"currency": "USD", | ||
"amount": "-50.00", | ||
"fee": "0.00", | ||
"net": "-50.00", | ||
"source_id": 460709370, | ||
"source_type": "adjustment", | ||
"source_order_id": null, | ||
"source_order_transaction_id": null, | ||
"processed_at": "2013-11-01" | ||
}, | ||
{ | ||
"id": 77412310, | ||
"type": "credit", | ||
"test": false, | ||
"payout_id": 623721858, | ||
"payout_status": "paid", | ||
"currency": "USD", | ||
"amount": "50.00", | ||
"fee": "0.00", | ||
"net": "50.00", | ||
"source_id": 374511569, | ||
"source_type": "Payments::Balance::AdjustmentReversal", | ||
"source_order_id": null, | ||
"source_order_transaction_id": null, | ||
"processed_at": "2013-11-01" | ||
}, | ||
{ | ||
"id": 1006917261, | ||
"type": "refund", | ||
"test": false, | ||
"payout_id": 623721858, | ||
"payout_status": "paid", | ||
"currency": "USD", | ||
"amount": "-3.45", | ||
"fee": "0.00", | ||
"net": "-3.45", | ||
"source_id": 1006917261, | ||
"source_type": "Payments::Refund", | ||
"source_order_id": 217130470, | ||
"source_order_transaction_id": 1006917261, | ||
"processed_at": "2013-11-01" | ||
} | ||
] | ||
} |
This file contains 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 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,122 @@ | ||
package goshopify | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
const ordersRiskBasePath = "orders" | ||
const ordersRiskResourceName = "risks" | ||
|
||
// OrderRiskService is an interface for interfacing with the orders Risk endpoints of | ||
// the Shopify API. | ||
// See: https://shopify.dev/docs/api/admin-rest/2023-10/resources/order-risk | ||
type OrderRiskService interface { | ||
List(int64, interface{}) ([]OrderRisk, error) | ||
ListWithPagination(int64, interface{}) ([]OrderRisk, *Pagination, error) | ||
Get(int64, int64, interface{}) (*OrderRisk, error) | ||
Create(int64, OrderRisk) (*OrderRisk, error) | ||
Update(int64, int64, OrderRisk) (*OrderRisk, error) | ||
Delete(int64, int64) error | ||
} | ||
|
||
// OrderRiskServiceOp handles communication with the order related methods of the | ||
// Shopify API. | ||
type OrderRiskServiceOp struct { | ||
client *Client | ||
} | ||
|
||
// Represents the result from the orders-risk/X.json endpoint | ||
type OrderRiskResource struct { | ||
OrderRisk *OrderRisk `json:"risk"` | ||
} | ||
|
||
// Represents the result from the orders-risk.json endpoint | ||
type OrdersRisksResource struct { | ||
OrderRisk []OrderRisk `json:"risks"` | ||
} | ||
type orderRiskRecommendation string | ||
|
||
const ( | ||
//order is fraudulent. | ||
OrderRecommendationCancel orderRiskRecommendation = "cancel" | ||
|
||
//medium level of risk that this order is fraudulent. | ||
OrderRecommendationInvestigate orderRiskRecommendation = "investigate" | ||
|
||
//level of risk that this order is fraudulent. | ||
OrderRecommendationAccept orderRiskRecommendation = "accept" | ||
) | ||
|
||
// A struct for all available order Risk list options. | ||
// See: https://shopify.dev/docs/api/admin-rest/2023-10/resources/order-risk#index | ||
type OrderRiskListOptions struct { | ||
ListOptions | ||
} | ||
|
||
// OrderRisk represents a Shopify order risk | ||
type OrderRisk struct { | ||
Id int64 `json:"id,omitempty"` | ||
CheckoutId int64 `json:"checkout_id,omitempty"` | ||
OrderId int64 `json:"order_id,omitempty"` | ||
CauseCancel bool `json:"cause_cancel,omitempty"` | ||
Display bool `json:"display,omitempty"` | ||
MerchantMessage string `json:"merchant_message,omitempty"` | ||
Message string `json:"message,omitempty"` | ||
Score string `json:"score,omitempty"` | ||
Source string `json:"source,omitempty"` | ||
Recommendation orderRiskRecommendation `json:"recommendation,omitempty"` | ||
} | ||
|
||
// List OrderRisk | ||
func (s *OrderRiskServiceOp) List(orderId int64, options interface{}) ([]OrderRisk, error) { | ||
orders, _, err := s.ListWithPagination(orderId, options) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return orders, nil | ||
} | ||
|
||
func (s *OrderRiskServiceOp) ListWithPagination(orderId int64, options interface{}) ([]OrderRisk, *Pagination, error) { | ||
path := fmt.Sprintf("%s/%d/%s.json", ordersRiskBasePath, orderId, ordersRiskResourceName) | ||
resource := new(OrdersRisksResource) | ||
|
||
pagination, err := s.client.ListWithPagination(path, resource, options) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return resource.OrderRisk, pagination, nil | ||
} | ||
|
||
// Get individual order | ||
func (s *OrderRiskServiceOp) Get(orderID int64, riskID int64, options interface{}) (*OrderRisk, error) { | ||
path := fmt.Sprintf("%s/%d/%s/%d.json", ordersRiskBasePath, orderID, ordersRiskResourceName, riskID) | ||
resource := new(OrderRiskResource) | ||
err := s.client.Get(path, resource, options) | ||
return resource.OrderRisk, err | ||
} | ||
|
||
// Create order | ||
func (s *OrderRiskServiceOp) Create(orderID int64, orderRisk OrderRisk) (*OrderRisk, error) { | ||
path := fmt.Sprintf("%s/%d/%s.json", ordersRiskBasePath, orderID, ordersRiskResourceName) | ||
wrappedData := OrderRiskResource{OrderRisk: &orderRisk} | ||
resource := new(OrderRiskResource) | ||
err := s.client.Post(path, wrappedData, resource) | ||
return resource.OrderRisk, err | ||
} | ||
|
||
// Update order | ||
func (s *OrderRiskServiceOp) Update(orderID int64, riskID int64, orderRisk OrderRisk) (*OrderRisk, error) { | ||
path := fmt.Sprintf("%s/%d/%s/%d.json", ordersRiskBasePath, orderID, ordersRiskResourceName, riskID) | ||
wrappedData := OrderRiskResource{OrderRisk: &orderRisk} | ||
resource := new(OrderRiskResource) | ||
err := s.client.Put(path, wrappedData, resource) | ||
return resource.OrderRisk, err | ||
} | ||
|
||
// Delete order | ||
func (s *OrderRiskServiceOp) Delete(orderID int64, riskID int64) error { | ||
path := fmt.Sprintf("%s/%d/%s/%d.json", ordersRiskBasePath, orderID, ordersRiskResourceName, riskID) | ||
err := s.client.Delete(path) | ||
return err | ||
} |
Oops, something went wrong.