1
|
|
|
package examples |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"fmt" |
5
|
|
|
"log" |
6
|
|
|
"os" |
7
|
|
|
|
8
|
|
|
"github.com/VictorAvelar/mollie-api-go/mollie" |
9
|
|
|
) |
10
|
|
|
|
11
|
|
|
var ( |
12
|
|
|
config *mollie.Config |
13
|
|
|
client *mollie.Client |
14
|
|
|
paymentID string = "tr_WDqYK6vllg" |
15
|
|
|
chargebackID string = "chb_n9z0tp" |
16
|
|
|
) |
17
|
|
|
|
18
|
|
|
// Sets the mollie api token on a environment variable. |
19
|
|
|
func init() { |
20
|
|
|
_ = os.Setenv(mollie.APITokenEnv, "YOUR_API_TOKEN") |
21
|
|
|
config = mollie.NewConfig(true, mollie.APITokenEnv) |
22
|
|
|
client, _ = mollie.NewClient(nil, config) |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
// GetSingleGhargeback code samples shows how a payment chargeback for the matching |
26
|
|
|
// payment and chargeback id should be retrieved. |
27
|
|
|
func GetSingleGhargeback() { |
28
|
|
|
chargeback, err := client.Chargebacks.Get(paymentID, chargebackID, nil) |
29
|
|
|
if err != nil { |
30
|
|
|
log.Fatal(err) |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
fmt.Printf("%+v", chargeback) |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
// ListAllPaymentRelatedChargebacks code sample shows how to retrieve all received |
37
|
|
|
// chargebacks for a payment. |
38
|
|
|
func ListAllPaymentRelatedChargebacks() { |
39
|
|
|
list, err := client.Chargebacks.ListForPayment(paymentID, nil) |
40
|
|
|
|
41
|
|
|
if err != nil { |
42
|
|
|
log.Fatal(err) |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
for _, c := range list.Embedded.Chargebacks { |
46
|
|
|
fmt.Printf("%+v\n", c) |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
// ListAllPaymentsForAccount code sample shows how to retrieve all received |
51
|
|
|
// chargebacks for your account. |
52
|
|
|
func ListAllPaymentsForAccount() { |
53
|
|
|
list, err := client.Chargebacks.List(nil) |
54
|
|
|
|
55
|
|
|
if err != nil { |
56
|
|
|
log.Fatal(err) |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
for _, c := range list.Embedded.Chargebacks { |
60
|
|
|
fmt.Printf("%+v\n", c) |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// ListAllPaymentsWithOptions code sample shows how to retrieve all received |
65
|
|
|
// chargebacks for your account. |
66
|
|
|
func ListAllPaymentsWithOptions() { |
67
|
|
|
list, err := client.Chargebacks.List(&mollie.ListChargebackOptions{ |
68
|
|
|
Include: "payments", // will include the payments these chargebacks were issued for. |
69
|
|
|
}) |
70
|
|
|
|
71
|
|
|
if err != nil { |
72
|
|
|
log.Fatal(err) |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
for _, c := range list.Embedded.Chargebacks { |
76
|
|
|
fmt.Printf("%+v\n", c) |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|