github.com/stripe/stripe-go/v76@v76.25.0/paymentsource/client_test.go (about)

     1  package paymentsource
     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 TestSourceGet(t *testing.T) {
    12  	source, err := Get("card_123", &stripe.PaymentSourceParams{
    13  		Customer: stripe.String("cus_123"),
    14  	})
    15  	assert.Nil(t, err)
    16  	assert.NotNil(t, source)
    17  }
    18  
    19  func TestSourceList(t *testing.T) {
    20  	i := List(&stripe.PaymentSourceListParams{
    21  		Customer: stripe.String("cus_123"),
    22  	})
    23  
    24  	// Verify that we can get at least one source
    25  	assert.True(t, i.Next())
    26  	assert.Nil(t, i.Err())
    27  	assert.NotNil(t, i.PaymentSource())
    28  	assert.NotNil(t, i.PaymentSourceList())
    29  }
    30  
    31  func TestSourceNew(t *testing.T) {
    32  	params := &stripe.PaymentSourceParams{
    33  		Customer: stripe.String("cus_123"),
    34  		Source:   &stripe.PaymentSourceSourceParams{Token: stripe.String("tok_123")},
    35  	}
    36  
    37  	source, err := New(params)
    38  	assert.Nil(t, err)
    39  	assert.NotNil(t, source)
    40  }
    41  
    42  func TestSourceUpdate(t *testing.T) {
    43  	params := &stripe.PaymentSourceParams{
    44  		Customer: stripe.String("cus_123"),
    45  	}
    46  	params.AddMetadata("key", "value")
    47  
    48  	source, err := Update("card_123", params)
    49  	assert.Nil(t, err)
    50  	assert.NotNil(t, source)
    51  }
    52  
    53  func TestSourceVerify(t *testing.T) {
    54  	source, err := Verify("ba_123", &stripe.PaymentSourceVerifyParams{
    55  		Customer: stripe.String("cus_123"),
    56  		Amounts:  [2]int64{32, 45},
    57  	})
    58  	assert.Nil(t, err)
    59  	assert.NotNil(t, source)
    60  }
    61  
    62  func TestSourceObjectVerify(t *testing.T) {
    63  	source, err := Verify("src_123", &stripe.PaymentSourceVerifyParams{
    64  		Values: stripe.StringSlice([]string{
    65  			"32",
    66  			"45",
    67  		}),
    68  	})
    69  	assert.Nil(t, err)
    70  	assert.NotNil(t, source)
    71  }