github.com/stripe/stripe-go/v76@v76.25.0/setupintent_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 TestSetupIntentNextAction_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 SetupIntentNextAction
    23  	err = json.Unmarshal(bytes, &action)
    24  	assert.NoError(t, err)
    25  
    26  	assert.Equal(t, SetupIntentNextActionTypeRedirectToURL, action.Type)
    27  	assert.Equal(t, "https://stripe.com", action.RedirectToURL.URL)
    28  	assert.Equal(t, "https://stripe.com/return", action.RedirectToURL.ReturnURL)
    29  }