-
Notifications
You must be signed in to change notification settings - Fork 1
/
paymentMaker.go
75 lines (66 loc) · 1.99 KB
/
paymentMaker.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
package main
import "fmt"
import "wrapper/payments"
type PaymentMaker struct {
paymentProvider payments.IPaymentProvider
}
func (self *PaymentMaker) doAPayment() {
// create fabrics
customerFactory := payments.CustomerFactory{ IPaymentProvider: self.paymentProvider }
productFactory := payments.ProductFactory{ IPaymentProvider: self.paymentProvider }
orderFactory := payments.OrderFactory{ IPaymentProvider: self.paymentProvider }
// create a customer
customer, _ := customerFactory.New(&payments.CustomerParams{
Balance: 10000,
Desc: "Test Customer",
Email: "[email protected]",
BusinessVatID: "123456789",
Source: &payments.SourceParams{
Card: &payments.CardParams{
Name: "Tester",
Number: "4242424242424242",
Month: "06",
Year: "20",
Address1: "1234 Main Street",
Address2: "Apt 1",
City: "Anytown",
State: "CA",
},
},
})
// create a product
productFactory.NewWithSKU(&payments.ProductParams{
Name: "T-shirt",
}, &payments.SKUParams{
Price: 150,
Currency: "usd",
Inventory: payments.Inventory{Type: "infinite"},
})
// Get all existing products and parse SKUs
products := productFactory.List()
var skuItems []*payments.OrderItemParams
for _, product := range products {
skuItems = append(skuItems, &payments.OrderItemParams{
Type: "sku",
Parent: product.Skus.Values[0].ID,
Description: "Some description",
})
}
// create an order
order, _ := orderFactory.New(skuItems, &payments.OrderParams{
Shipping: &payments.ShippingParams{
Name: "Noah Davis",
Address: &payments.AddressParams{
Line1: "1234 Main Street",
City: "San Francisco",
Country: "US",
PostalCode: "94111",
},
},
})
// pay this recently created order
payedOrder, _ := orderFactory.Pay(order.ID, &payments.OrderPayParams{
Customer: customer.ID,
})
fmt.Println(payedOrder.ID)
}