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
|
|
|
customerID string = "cst_qPgbV2VkwT" |
13
|
|
|
subscriptionID string = "sub_8EjeBVgtEn" |
14
|
|
|
) |
15
|
|
|
|
16
|
|
|
// Sets the mollie api token on an environment variable |
17
|
|
|
func init() { |
18
|
|
|
_ = os.Setenv(mollie.APITokenEnv, "YOUR_API_TOKEN") |
19
|
|
|
_ = os.Setenv(mollie.OrgTokenEnv, "YOUR_ORG_TOKEN") |
20
|
|
|
|
21
|
|
|
config := mollie.NewConfig(true, mollie.APITokenEnv) |
22
|
|
|
client, _ = mollie.NewClient(nil, config) |
23
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
//CreateSubscription code sample for creating a subscription |
27
|
|
|
func CreateSubscription() { |
28
|
|
|
|
29
|
|
|
newSubscription := &mollie.Subscription{ |
30
|
|
|
Amount: &mollie.Amount{Currency: "EUR", Value: "25.00"}, |
31
|
|
|
Times: 4, |
32
|
|
|
Interval: "3 months", |
33
|
|
|
Description: "Quarterly payment", |
34
|
|
|
WebhookURL: "https://webshop.example.org/subscriptions/webhook/", |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
sub, err := client.Subscriptions.Create(customerID, newSubscription) |
38
|
|
|
|
39
|
|
|
if err != nil { |
40
|
|
|
log.Fatal(err) |
41
|
|
|
} |
42
|
|
|
fmt.Println(sub) |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
//GetSubscription code sample for getting a specific subscription using a customer ID |
46
|
|
|
func GetSubscription() { |
47
|
|
|
|
48
|
|
|
sub, err := client.Subscriptions.Get(customerID, subscriptionID) |
49
|
|
|
|
50
|
|
|
if err != nil { |
51
|
|
|
log.Fatal(err) |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
fmt.Println(sub) |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
//UpdateSubscription code sample for updating a specific subscription |
58
|
|
|
func UpdateSubscription() { |
59
|
|
|
|
60
|
|
|
updatedSubscription := &mollie.Subscription{ |
61
|
|
|
Amount: &mollie.Amount{Currency: "EUR", Value: "10.00"}, |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
sub, err := client.Subscriptions.Update(customerID, subscriptionID, updatedSubscription) |
65
|
|
|
|
66
|
|
|
if err != nil { |
67
|
|
|
log.Fatal(err) |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
fmt.Println(sub) |
71
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
//CancelSubscription code sample for canceling a subscription |
75
|
|
|
func CancelSubscription() { |
76
|
|
|
|
77
|
|
|
sub, err := client.Subscriptions.Delete(customerID, subscriptionID) |
78
|
|
|
|
79
|
|
|
if err != nil { |
80
|
|
|
log.Fatal(err) |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
fmt.Println(sub) |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
//ListSubscriptions code sample for getting a list of subscriptions for a certain customer |
87
|
|
|
func ListSubscriptions() { |
88
|
|
|
|
89
|
|
|
options := &mollie.SubscriptionListOptions{Limit: 5} |
90
|
|
|
|
91
|
|
|
list, err := client.Subscriptions.List(customerID, options) |
92
|
|
|
|
93
|
|
|
if err != nil { |
94
|
|
|
log.Fatal(err) |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
fmt.Println(list) |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
//ListAllSubscriptions code sample to retrieving all subscriptions for the current website profile |
101
|
|
|
func ListAllSubscriptions() { |
102
|
|
|
|
103
|
|
|
listOptions := &mollie.SubscriptionListOptions{ProfileID: "pfl_K4zQxvyTVH"} |
104
|
|
|
all, err := client.Subscriptions.All(listOptions) |
105
|
|
|
|
106
|
|
|
if err != nil { |
107
|
|
|
log.Fatal(err) |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
fmt.Println(all) |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
//ListSubscriptionPayments code sample for retrieving all payments of a specific subscription for a certain customer |
114
|
|
|
func ListSubscriptionPayments() { |
115
|
|
|
|
116
|
|
|
options := &mollie.SubscriptionListOptions{Limit: 5} |
117
|
|
|
|
118
|
|
|
list, err := client.Subscriptions.GetPayments(customerID, subscriptionID, options) |
119
|
|
|
|
120
|
|
|
if err != nil { |
121
|
|
|
log.Fatal(err) |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
fmt.Println(list.Embedded.Payments) |
125
|
|
|
} |
126
|
|
|
|