GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#93)
by
unknown
01:10
created

main.createCustomer   A

Complexity

Conditions 2

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
dl 0
loc 14
rs 9.85
c 0
b 0
f 0
nop 1
1
package main
2
3
import (
4
	"fmt"
5
	"github.com/VictorAvelar/mollie-api-go/mollie"
6
	"log"
7
	"os"
8
)
9
10
/**
11
Example app to show the following Mollie features:
12
 - Get customer
13
 - Update customer
14
 - Delete customer
15
 - List customers
16
 - Create customer payment
17
 - List customer payments
18
*/
19
20
func main() {
21
	fmt.Printf("Connecting to Mollie....\n")
22
	m := createMollie()
23
24
	//create customer
25
	cs := createCustomer(m)
26
27
	// get customer
28
	cs = getCustomer(cs, m)
29
30
	//update customer
31
	updateCustomer(cs, m)
32
33
	//list all customers
34
	listAllCustomers(m)
35
36
	//create payment for a single customer
37
	createCustomerPayment(cs, m)
38
39
	//get all payments for a particular customer
40
	getCustomerPayments(cs, m)
41
42
	os.Exit(0)
43
}
44
45
//getCustomerPayments extract all payments for a particular customer from mollie
46
func getCustomerPayments(cs *mollie.Customer, m *mollie.Client) {
47
	// List customer payment
48
	fmt.Printf("Listing customer ID %s payments\n", cs.ID)
49
	pl, err := m.Customers.GetPayments(cs.ID, nil)
50
	if err != nil {
51
		log.Fatal(err)
52
	}
53
54
	fmt.Printf("....customer with id %s has %d payments", cs.ID, pl.Count)
55
}
56
57
//createCustomerPayment create a single payment for a particular customer from mollie
58
func createCustomerPayment(cs *mollie.Customer, m *mollie.Client)  {
59
	// Create customer payment
60
	fmt.Printf("Creating payment for customer  with id %s \n", cs.ID)
61
	var bt = mollie.BankTransfer
62
63
	var p = mollie.Payment{
64
		Amount: &mollie.Amount{
65
			Currency: "EUR",
66
			Value:    "10.12",
67
		},
68
		Description: "Order #12345",
69
		Method:      &bt,
70
		RedirectURL: "https://webshop.example.org/order/12345/",
71
		WebhookURL:  "https://webshop.example.org/payments/webhook/",
72
	}
73
	pp, err := m.Customers.CreatePayment(cs.ID, p)
74
	if err != nil {
75
		log.Fatal(err)
76
	}
77
	fmt.Printf("....created new payment with the following info - ID %s, currency : %s, "+
78
		"value : %s ",
79
		pp.ID, pp.Amount.Currency, pp.Amount.Value)
80
}
81
82
//listAllCustomers list all customers from mollie
83
func listAllCustomers(m *mollie.Client) {
84
	fmt.Printf("List all customers....\n")
85
	output, err := m.Customers.List(nil)
86
	if err != nil {
87
		log.Fatal(err)
88
	}
89
	fmt.Printf("....total number customer - %d\n", output.Count)
90
}
91
92
//updateCustomer update email of a particular customer from mollie
93
func updateCustomer(cs *mollie.Customer, m *mollie.Client) {
94
	fmt.Printf("Updating customer with id %s\n", cs.ID)
95
	var uc = mollie.Customer{
96
		Email: "[email protected]",
97
	}
98
	cs, err := m.Customers.Update(cs.ID, uc)
99
	if err != nil {
100
		log.Fatal(err)
101
	}
102
	fmt.Printf("....existing customer ID %s email has been updated to %s", cs.ID, cs.Email)
103
}
104
105
//getCustomer extract a particular customer from mollie
106
func getCustomer(cs *mollie.Customer, m *mollie.Client) *mollie.Customer {
107
	//2. Get customer
108
	fmt.Printf("Retrieving customer information with id %s\n", cs.ID)
109
	cs, err := m.Customers.Get(cs.ID)
110
	if err != nil {
111
		log.Fatal(err)
112
	}
113
	fmt.Printf("....existing customer - name %s, ID %s, email %s\n", cs.Name, cs.ID, cs.Email)
114
	return cs
115
}
116
117
//createCustomer create a single customer from mollie
118
func createCustomer(m *mollie.Client) *mollie.Customer {
119
	var c = mollie.Customer{
120
		Name:  "testkingkong",
121
		Email: "[email protected]",
122
	}
123
	fmt.Printf("Creating new customer with the following info - name : %s , email : %s\n", c.Name,
124
		c.Email)
125
	cs, err := m.Customers.Create(c)
126
	if err != nil {
127
		log.Fatal(err)
128
	}
129
130
	fmt.Printf("....new customer created has ID %s\n", cs.ID)
131
	return cs
132
}
133
134
// createMollie create a mollie connection
135
func createMollie() *mollie.Client {
136
	config := mollie.NewConfig(false, mollie.APITokenEnv)
137
	m, err := mollie.NewClient(nil, config)
138
	if err != nil {
139
		log.Fatal(err)
140
	}
141
	return m
142
}
143