This repository has been archived by the owner on Jan 18, 2018. It is now read-only.
/
payers.go
99 lines (80 loc) · 2.18 KB
/
payers.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package api
import (
"errors"
"github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/customer"
"github.com/stripe/stripe-go/sub"
)
type payerProxy interface {
createCustomer(userID, email, payToken string) (string, error)
create(userID, plan, token string) (string, error)
update(subID, plan, token string) (string, error)
delete(subID string) error
}
type StripeProxy struct {
}
func (StripeProxy) create(userID, plan, token string) (string, error) {
s, err := sub.New(&stripe.SubParams{
Customer: userID,
Plan: plan,
})
if err != nil {
return "", err
}
return s.ID, nil
}
func (StripeProxy) update(subID, plan, token string) (string, error) {
s, err := sub.Update(subID, &stripe.SubParams{
Plan: plan,
})
if err != nil {
return "", err
}
return s.ID, nil
}
func (StripeProxy) delete(subID string) error {
_, err := sub.Cancel(subID, &stripe.SubParams{})
return err
}
func (StripeProxy) createCustomer(userID, email, payToken string) (string, error) {
params := &stripe.CustomerParams{
Email: email,
Source: &stripe.SourceParams{
Token: payToken,
},
}
params.Meta = map[string]string{"nf_id": userID}
c, err := customer.New(params)
if err != nil {
return "", err
}
return c.ID, nil
}
/*
POST /subscriptions/members/smashing
{first_name: Matt, last_name: Biilmann, strie_token: "sdfsdfsfsd"}
Signed by {user_id: 1234}
---
existingUser = db.findUser({user_id: 1234})
if existingUser
stripApi.subscribeToPlan(existingUser.customer_id, params.plan, source: params.stripe_token)
else
customer = stripeApi.createCustomer({user_id: ...})
user.create({customer_id: customer.id})
stripeApi.subscripbeToPlan(user.customer_id, params.plan, source: params.stripe_token)
end
*/
type errorProxy struct {
}
func (errorProxy) createCustomer(_, _, _ string) (string, error) {
return "", errors.New("No payer proxy provided")
}
func (errorProxy) create(userID, plan, token string) (string, error) {
return "", errors.New("No payer proxy provided")
}
func (errorProxy) update(subID, plan, token string) (string, error) {
return "", errors.New("No payer proxy provided")
}
func (errorProxy) delete(subID string) error {
return errors.New("No payer proxy provided")
}