@@ -19,6 +19,8 @@ func NewClient(cfg api.Config) (*Client, error) {
19
19
chargesStub : stub .NewCharges (),
20
20
checkouts : api .NewCheckouts (cfg ),
21
21
checkoutsStub : stub .NewCheckouts (),
22
+ invoices : api .NewInvoices (cfg ),
23
+ invoicesStub : stub .NewInvoices (),
22
24
}, nil
23
25
}
24
26
@@ -28,6 +30,8 @@ type Client struct {
28
30
chargesStub api.ChargesItf
29
31
checkouts api.CheckoutsItf
30
32
checkoutsStub api.CheckoutsItf
33
+ invoices api.InvoicesItf
34
+ invoicesStub api.InvoicesItf
31
35
}
32
36
33
37
// CreateCharge charge a customer with certain amount of currency.
@@ -36,7 +40,7 @@ type Client struct {
36
40
// Once a charge is created a customer must broadcast a payment
37
41
// to the blockchain before the charge expires.
38
42
// Reference: https://commerce.coinbase.com/docs/api/#create-a-charge
39
- func (c Client ) CreateCharge (ctx context.Context , req * entity.CreateChargeReq ) (* entity.CreateChargeResp , error ) {
43
+ func (c * Client ) CreateCharge (ctx context.Context , req * entity.CreateChargeReq ) (* entity.CreateChargeResp , error ) {
40
44
if stub .Ok (ctx ) {
41
45
return c .chargesStub .Create (ctx , req )
42
46
}
@@ -47,7 +51,7 @@ func (c Client) CreateCharge(ctx context.Context, req *entity.CreateChargeReq) (
47
51
// Supply the unique charge code or id that was returned when the charge was created.
48
52
// This information is also returned when a charge is first created.
49
53
// Reference: https://commerce.coinbase.com/docs/api/#show-a-charge
50
- func (c Client ) ShowCharge (ctx context.Context , req * entity.ShowChargeReq ) (* entity.ShowChargeResp , error ) {
54
+ func (c * Client ) ShowCharge (ctx context.Context , req * entity.ShowChargeReq ) (* entity.ShowChargeResp , error ) {
51
55
if err := req .Validate (); err != nil {
52
56
return nil , err
53
57
}
@@ -59,7 +63,7 @@ func (c Client) ShowCharge(ctx context.Context, req *entity.ShowChargeReq) (*ent
59
63
60
64
// ListCharges lists all the charges.
61
65
// Reference: https://commerce.coinbase.com/docs/api/#list-charges
62
- func (c Client ) ListCharges (ctx context.Context , req * entity.ListChargesReq ) (* entity.ListChargesResp , error ) {
66
+ func (c * Client ) ListCharges (ctx context.Context , req * entity.ListChargesReq ) (* entity.ListChargesResp , error ) {
63
67
if stub .Ok (ctx ) {
64
68
return c .chargesStub .List (ctx , req )
65
69
}
@@ -75,7 +79,7 @@ func (c Client) ListCharges(ctx context.Context, req *entity.ListChargesReq) (*e
75
79
// Once payment is detected, charge can no longer be canceled.
76
80
//
77
81
// Reference: https://commerce.coinbase.com/docs/api/#cancel-a-charge
78
- func (c Client ) CancelCharge (ctx context.Context , req * entity.CancelChargeReq ) (* entity.CancelChargeResp , error ) {
82
+ func (c * Client ) CancelCharge (ctx context.Context , req * entity.CancelChargeReq ) (* entity.CancelChargeResp , error ) {
79
83
if err := req .Validate (); err != nil {
80
84
return nil , err
81
85
}
@@ -93,7 +97,7 @@ func (c Client) CancelCharge(ctx context.Context, req *entity.CancelChargeReq) (
93
97
// Only unresolved charges can be successfully resolved
94
98
//
95
99
// Reference: https://commerce.coinbase.com/docs/api/#resolve-a-charge
96
- func (c Client ) ResolveCharge (ctx context.Context , req * entity.ResolveChargeReq ) (* entity.ResolveChargeResp , error ) {
100
+ func (c * Client ) ResolveCharge (ctx context.Context , req * entity.ResolveChargeReq ) (* entity.ResolveChargeResp , error ) {
97
101
if err := req .Validate (); err != nil {
98
102
return nil , err
99
103
}
@@ -105,7 +109,7 @@ func (c Client) ResolveCharge(ctx context.Context, req *entity.ResolveChargeReq)
105
109
106
110
// ListCheckouts lists all the checkouts.
107
111
// Reference: https://commerce.coinbase.com/docs/api/#list-checkouts
108
- func (c Client ) ListCheckouts (ctx context.Context , req * entity.ListCheckoutsReq ) (* entity.ListCheckoutsResp , error ) {
112
+ func (c * Client ) ListCheckouts (ctx context.Context , req * entity.ListCheckoutsReq ) (* entity.ListCheckoutsResp , error ) {
109
113
if stub .Ok (ctx ) {
110
114
return c .checkoutsStub .List (ctx , req )
111
115
}
@@ -114,7 +118,7 @@ func (c Client) ListCheckouts(ctx context.Context, req *entity.ListCheckoutsReq)
114
118
115
119
// ShowCheckout show a single checkout.
116
120
// Reference: https://commerce.coinbase.com/docs/api/#show-a-checkout
117
- func (c Client ) ShowCheckout (ctx context.Context , req * entity.ShowCheckoutReq ) (* entity.ShowCheckoutResp , error ) {
121
+ func (c * Client ) ShowCheckout (ctx context.Context , req * entity.ShowCheckoutReq ) (* entity.ShowCheckoutResp , error ) {
118
122
if err := req .Validate (); err != nil {
119
123
return nil , err
120
124
}
@@ -126,7 +130,7 @@ func (c Client) ShowCheckout(ctx context.Context, req *entity.ShowCheckoutReq) (
126
130
127
131
// CreateCheckout create a new checkout.
128
132
// Reference: https://commerce.coinbase.com/docs/api/#create-a-checkout
129
- func (c Client ) CreateCheckout (ctx context.Context , req * entity.CreateCheckoutReq ) (* entity.CreateCheckoutResp , error ) {
133
+ func (c * Client ) CreateCheckout (ctx context.Context , req * entity.CreateCheckoutReq ) (* entity.CreateCheckoutResp , error ) {
130
134
if stub .Ok (ctx ) {
131
135
return c .checkoutsStub .Create (ctx , req )
132
136
}
@@ -135,7 +139,7 @@ func (c Client) CreateCheckout(ctx context.Context, req *entity.CreateCheckoutRe
135
139
136
140
// UpdateCheckout update a checkout.
137
141
// Reference: https://commerce.coinbase.com/docs/api/#update-a-checkout
138
- func (c Client ) UpdateCheckout (ctx context.Context , req * entity.UpdateCheckoutReq ) (* entity.UpdateCheckoutResp , error ) {
142
+ func (c * Client ) UpdateCheckout (ctx context.Context , req * entity.UpdateCheckoutReq ) (* entity.UpdateCheckoutResp , error ) {
139
143
if err := req .Validate (); err != nil {
140
144
return nil , err
141
145
}
@@ -147,7 +151,7 @@ func (c Client) UpdateCheckout(ctx context.Context, req *entity.UpdateCheckoutRe
147
151
148
152
// DeleteCheckout delete a checkout.
149
153
// Reference: https://commerce.coinbase.com/docs/api/#delete-a-checkout
150
- func (c Client ) DeleteCheckout (ctx context.Context , req * entity.DeleteCheckoutReq ) (* entity.DeleteCheckoutResp , error ) {
154
+ func (c * Client ) DeleteCheckout (ctx context.Context , req * entity.DeleteCheckoutReq ) (* entity.DeleteCheckoutResp , error ) {
151
155
if err := req .Validate (); err != nil {
152
156
return nil , err
153
157
}
@@ -156,3 +160,74 @@ func (c Client) DeleteCheckout(ctx context.Context, req *entity.DeleteCheckoutRe
156
160
}
157
161
return c .checkouts .Delete (ctx , req )
158
162
}
163
+
164
+ // ListInvoices lists all the invoices.
165
+ // Reference: https://commerce.coinbase.com/docs/api/#list-invoices
166
+ func (c * Client ) ListInvoices (ctx context.Context , req * entity.ListInvoicesReq ) (* entity.ListInvoicesResp , error ) {
167
+ if stub .Ok (ctx ) {
168
+ return c .invoicesStub .List (ctx , req )
169
+ }
170
+ return c .invoices .List (ctx , req )
171
+ }
172
+
173
+ // ShowInvoice retrieves the details of an invoice that has been previously created.
174
+ // Supply the unique invoice code or id that was returned when the charge was created.
175
+ // This information is also returned when an invoice is first created.
176
+ // Reference: https://commerce.coinbase.com/docs/api/#show-an-invoice
177
+ func (c * Client ) ShowInvoice (ctx context.Context , req * entity.ShowInvoiceReq ) (* entity.ShowInvoiceResp , error ) {
178
+ if err := req .Validate (); err != nil {
179
+ return nil , err
180
+ }
181
+ if stub .Ok (ctx ) {
182
+ return c .invoicesStub .Show (ctx , req )
183
+ }
184
+ return c .invoices .Show (ctx , req )
185
+ }
186
+
187
+ // CreateInvoice to send an invoice in cryptocurrency,
188
+ // you need to create an invoice object and provide the user
189
+ // with the hosted url where they will be able to pay.
190
+ // Once an invoice is viewed at the hosted url,
191
+ // a charge will be generated on the invoice.
192
+ // Reference: https://commerce.coinbase.com/docs/api/#create-an-invoice
193
+ func (c * Client ) CreateInvoice (ctx context.Context , req * entity.CreateInvoiceReq ) (* entity.CreateInvoiceResp , error ) {
194
+ if stub .Ok (ctx ) {
195
+ return c .invoicesStub .Create (ctx , req )
196
+ }
197
+ return c .invoices .Create (ctx , req )
198
+ }
199
+
200
+ // VoidInvoice voids an invoice that has been previously created.
201
+ // Supply the unique invoice code or id that was returned when the charge was created.
202
+ //
203
+ // Note:
204
+ // Only invoices with OPEN or VIEWED status can be voided.
205
+ // Once a payment is detected, the invoice can no longer be voided.
206
+ //
207
+ // Reference: https://commerce.coinbase.com/docs/api/#void-an-invoice
208
+ func (c * Client ) VoidInvoice (ctx context.Context , req * entity.VoidInvoiceReq ) (* entity.VoidInvoiceResp , error ) {
209
+ if err := req .Validate (); err != nil {
210
+ return nil , err
211
+ }
212
+ if stub .Ok (ctx ) {
213
+ return c .invoicesStub .Void (ctx , req )
214
+ }
215
+ return c .invoices .Void (ctx , req )
216
+ }
217
+
218
+ // ResolveInvoice resolve an invoice that has been previously marked as unresolved.
219
+ // Supply the unique invoice code or id that was returned when the charge was created.
220
+ //
221
+ // Note:
222
+ // Only invoices with an unresolved charge can be successfully resolved.
223
+ //
224
+ // Reference: https://commerce.coinbase.com/docs/api/#resolve-an-invoice
225
+ func (c * Client ) ResolveInvoice (ctx context.Context , req * entity.ResolveInvoiceReq ) (* entity.ResolveInvoiceResp , error ) {
226
+ if err := req .Validate (); err != nil {
227
+ return nil , err
228
+ }
229
+ if stub .Ok (ctx ) {
230
+ return c .invoicesStub .Resolve (ctx , req )
231
+ }
232
+ return c .invoices .Resolve (ctx , req )
233
+ }
0 commit comments