github.com/stripe/stripe-go/v76@v76.25.0/paymentintent_test.go (about) 1 package stripe 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 assert "github.com/stretchr/testify/require" 8 ) 9 10 func TestPaymentIntentNextAction_UnmarshalJSON(t *testing.T) { 11 actionData := map[string]interface{}{ 12 "redirect_to_url": map[string]interface{}{ 13 "return_url": "https://stripe.com/return", 14 "url": "https://stripe.com", 15 }, 16 "type": "redirect_to_url", 17 } 18 19 bytes, err := json.Marshal(&actionData) 20 assert.NoError(t, err) 21 22 var action PaymentIntentNextAction 23 err = json.Unmarshal(bytes, &action) 24 assert.NoError(t, err) 25 26 assert.Equal(t, PaymentIntentNextActionTypeRedirectToURL, action.Type) 27 assert.Equal(t, "https://stripe.com", action.RedirectToURL.URL) 28 assert.Equal(t, "https://stripe.com/return", action.RedirectToURL.ReturnURL) 29 } 30 31 func TestPaymentIntent_UnmarshalJSON(t *testing.T) { 32 intentData := map[string]interface{}{ 33 "id": "pi_123", 34 "object": "payment_intent", 35 "latest_charge": map[string]interface{}{ 36 "id": "ch_123", 37 "object": "charge", 38 }, 39 "payment_method_types": []interface{}{ 40 "card", 41 }, 42 } 43 44 bytes, err := json.Marshal(&intentData) 45 assert.NoError(t, err) 46 47 var intent PaymentIntent 48 err = json.Unmarshal(bytes, &intent) 49 assert.NoError(t, err) 50 51 assert.Equal(t, "pi_123", intent.ID) 52 53 assert.Equal(t, "ch_123", intent.LatestCharge.ID) 54 assert.Equal(t, 1, len(intent.PaymentMethodTypes)) 55 }