-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaymentintent.go
55 lines (45 loc) · 1.58 KB
/
paymentintent.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
package stripego
import (
"github.com/stripe/stripe-go/v74"
"github.com/stripe/stripe-go/v74/paymentintent"
)
// CreatePaymentIntent - create a new PaymentIntent object in stripe
func CreatePaymentIntent(sk string, piReq stripe.PaymentIntentParams) (piRes *stripe.PaymentIntent, err error) {
// stripe secret key
stripe.Key = sk
// create a PaymentIntent
piRes, err = paymentintent.New(&piReq)
return
}
// UpdateAmountPaymentIntent - update the amount of an existing PaymentIntent object in stripe
func UpdateAmountPaymentIntent(sk, paymentIntentID string, newAmount int64) (piRes *stripe.PaymentIntent, err error) {
// stripe secret key
stripe.Key = sk
// create PaymentIntentParams with amount
params := &stripe.PaymentIntentParams{
Amount: stripe.Int64(newAmount),
}
// update the PaymentIntent
piRes, err = paymentintent.Update(paymentIntentID, params)
return
}
// UpdateMethodPaymentIntent - update the payment method of an existing PaymentIntent object in stripe
func UpdateMethodPaymentIntent(sk, paymentIntentID string, pm *stripe.PaymentMethod) (piRes *stripe.PaymentIntent, err error) {
// stripe secret key
stripe.Key = sk
// update the PaymentIntent
piRes, err = paymentintent.Update(
paymentIntentID,
&stripe.PaymentIntentParams{
PaymentMethod: stripe.String(pm.ID),
},
)
return
}
// CancelPaymentIntent - cancel an existing PaymentIntent object in stripe
func CancelPaymentIntent(sk, paymentIntentID string) (piRes *stripe.PaymentIntent, err error) {
// stripe secret key
stripe.Key = sk
piRes, err = paymentintent.Cancel(paymentIntentID, nil)
return
}