github.com/stripe/stripe-go/v76@v76.25.0/paymentintent/client_test.go (about) 1 package paymentintent 2 3 import ( 4 "testing" 5 6 assert "github.com/stretchr/testify/require" 7 stripe "github.com/stripe/stripe-go/v76" 8 _ "github.com/stripe/stripe-go/v76/testing" 9 ) 10 11 func TestPaymentIntentCancel(t *testing.T) { 12 intent, err := Cancel("pi_123", &stripe.PaymentIntentCancelParams{ 13 CancellationReason: stripe.String(string(stripe.PaymentIntentCancellationReasonRequestedByCustomer)), 14 }) 15 assert.Nil(t, err) 16 assert.NotNil(t, intent) 17 } 18 19 func TestPaymentIntentCapture(t *testing.T) { 20 intent, err := Capture("pi_123", &stripe.PaymentIntentCaptureParams{ 21 AmountToCapture: stripe.Int64(123), 22 }) 23 assert.Nil(t, err) 24 assert.NotNil(t, intent) 25 } 26 27 func TestPaymentIntentConfirm(t *testing.T) { 28 intent, err := Confirm("pi_123", &stripe.PaymentIntentConfirmParams{ 29 ReturnURL: stripe.String("https://stripe.com/return"), 30 OffSession: stripe.Bool(true), 31 }) 32 assert.Nil(t, err) 33 assert.NotNil(t, intent) 34 } 35 36 func TestPaymentIntentGet(t *testing.T) { 37 intent, err := Get("pi_123", nil) 38 assert.Nil(t, err) 39 assert.NotNil(t, intent) 40 } 41 42 func TestPaymentIntentList(t *testing.T) { 43 i := List(&stripe.PaymentIntentListParams{}) 44 45 // Verify that we can get at least one payment intent 46 assert.True(t, i.Next()) 47 assert.Nil(t, i.Err()) 48 assert.NotNil(t, i.PaymentIntent()) 49 assert.NotNil(t, i.PaymentIntentList()) 50 } 51 52 func TestPaymentIntentNew(t *testing.T) { 53 intent, err := New(&stripe.PaymentIntentParams{ 54 Amount: stripe.Int64(123), 55 Currency: stripe.String(string(stripe.CurrencyUSD)), 56 PaymentMethodTypes: stripe.StringSlice([]string{ 57 "card", 58 }), 59 }) 60 assert.Nil(t, err) 61 assert.NotNil(t, intent) 62 } 63 64 func TestPaymentIntentUpdate(t *testing.T) { 65 intent, err := Update("pi_123", &stripe.PaymentIntentParams{ 66 Params: stripe.Params{ 67 Metadata: map[string]string{ 68 "foo": "bar", 69 }, 70 }, 71 }) 72 assert.Nil(t, err) 73 assert.NotNil(t, intent) 74 }