forked from bold-commerce/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
applicationcharge.go
79 lines (67 loc) · 3.07 KB
/
applicationcharge.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package goshopify
import (
"fmt"
"time"
"github.com/shopspring/decimal"
)
const applicationChargesBasePath = "admin/application_charges"
// ApplicationChargeService is an interface for interacting with the
// ApplicationCharge endpoints of the Shopify API.
// See https://help.shopify.com/api/reference/billing/applicationcharge
type ApplicationChargeService interface {
Create(ApplicationCharge) (*ApplicationCharge, error)
Get(int, interface{}) (*ApplicationCharge, error)
List(interface{}) ([]ApplicationCharge, error)
Activate(ApplicationCharge) (*ApplicationCharge, error)
}
type ApplicationChargeServiceOp struct {
client *Client
}
type ApplicationCharge struct {
ID int `json:"id"`
Name string `json:"name"`
APIClientID int `json:"api_client_id"`
Price *decimal.Decimal `json:"price"`
Status string `json:"status"`
ReturnURL string `json:"return_url"`
Test *bool `json:"test"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
ChargeType *string `json:"charge_type"`
DecoratedReturnURL string `json:"decorated_return_url"`
ConfirmationURL string `json:"confirmation_url"`
}
// ApplicationChargeResource represents the result from the
// admin/application_charges{/X{/activate.json}.json}.json endpoints.
type ApplicationChargeResource struct {
Charge *ApplicationCharge `json:"application_charge"`
}
// ApplicationChargesResource represents the result from the
// admin/application_charges.json endpoint.
type ApplicationChargesResource struct {
Charges []ApplicationCharge `json:"application_charges"`
}
// Create creates new application charge.
func (a ApplicationChargeServiceOp) Create(charge ApplicationCharge) (*ApplicationCharge, error) {
path := fmt.Sprintf("%s.json", applicationChargesBasePath)
resource := &ApplicationChargeResource{}
return resource.Charge, a.client.Post(path, ApplicationChargeResource{Charge: &charge}, resource)
}
// Get gets individual application charge.
func (a ApplicationChargeServiceOp) Get(chargeID int, options interface{}) (*ApplicationCharge, error) {
path := fmt.Sprintf("%s/%d.json", applicationChargesBasePath, chargeID)
resource := &ApplicationChargeResource{}
return resource.Charge, a.client.Get(path, resource, options)
}
// List gets all application charges.
func (a ApplicationChargeServiceOp) List(options interface{}) ([]ApplicationCharge, error) {
path := fmt.Sprintf("%s.json", applicationChargesBasePath)
resource := &ApplicationChargesResource{}
return resource.Charges, a.client.Get(path, resource, options)
}
// Activate activates application charge.
func (a ApplicationChargeServiceOp) Activate(charge ApplicationCharge) (*ApplicationCharge, error) {
path := fmt.Sprintf("%s/%d/activate.json", applicationChargesBasePath, charge.ID)
resource := &ApplicationChargeResource{}
return resource.Charge, a.client.Post(path, ApplicationChargeResource{Charge: &charge}, resource)
}