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

     1  package paymentmethod
     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 TestPaymentMethodAttach(t *testing.T) {
    12  	params := &stripe.PaymentMethodAttachParams{
    13  		Customer: stripe.String("cus_123"),
    14  	}
    15  	pm, err := Attach("pm_123", params)
    16  	assert.Nil(t, err)
    17  	assert.NotNil(t, pm)
    18  }
    19  
    20  func TestPaymentMethodDetach(t *testing.T) {
    21  	params := &stripe.PaymentMethodDetachParams{}
    22  	pm, err := Detach("pm_123", params)
    23  	assert.Nil(t, err)
    24  	assert.NotNil(t, pm)
    25  }
    26  
    27  func TestPaymentMethodGet(t *testing.T) {
    28  	pm, err := Get("pm_123", nil)
    29  	assert.Nil(t, err)
    30  	assert.NotNil(t, pm)
    31  }
    32  
    33  func TestPaymentMethodList(t *testing.T) {
    34  	params := &stripe.PaymentMethodListParams{
    35  		Customer: stripe.String("cus_123"),
    36  		Type:     stripe.String(string(stripe.PaymentMethodTypeCard)),
    37  	}
    38  	i := List(params)
    39  
    40  	// Verify that we can get at least one pm
    41  	assert.True(t, i.Next())
    42  	assert.Nil(t, i.Err())
    43  	assert.NotNil(t, i.PaymentMethod())
    44  	assert.NotNil(t, i.PaymentMethodList())
    45  }
    46  
    47  func TestPaymentMethodNew(t *testing.T) {
    48  	pm, err := New(&stripe.PaymentMethodParams{
    49  		Type: stripe.String(string(stripe.PaymentMethodTypeCard)),
    50  		Card: &stripe.PaymentMethodCardParams{
    51  			Token: stripe.String("tok_123"),
    52  		},
    53  	})
    54  	assert.Nil(t, err)
    55  	assert.NotNil(t, pm)
    56  }
    57  
    58  func TestPaymentMethodUpdate(t *testing.T) {
    59  	params := &stripe.PaymentMethodParams{
    60  		Params: stripe.Params{
    61  			Metadata: map[string]string{
    62  				"foo": "bar",
    63  			},
    64  		},
    65  	}
    66  	pm, err := Update("pm_123", params)
    67  	assert.Nil(t, err)
    68  	assert.NotNil(t, pm)
    69  }