コード例 #1
0
ファイル: client_test.go プロジェクト: carriercomm/stripe-go
func TestAccountUpdateWithToken(t *testing.T) {
	params := &stripe.AccountParams{
		Managed: true,
		Country: "CA",
	}

	acct, _ := New(params)

	tokenParams := &stripe.TokenParams{
		Bank: &stripe.BankAccountParams{
			Country: "US",
			Routing: "110000000",
			Account: "000123456789",
		},
	}

	tok, _ := token.New(tokenParams)

	params = &stripe.AccountParams{
		ExternalAccount: &stripe.AccountExternalAccountParams{
			Token: tok.ID,
		},
	}

	_, err := Update(acct.ID, params)
	if err != nil {
		t.Error(err)
	}
}
コード例 #2
0
ファイル: client_test.go プロジェクト: carriercomm/stripe-go
func TestAccountUpdateWithCardToken(t *testing.T) {
	params := &stripe.AccountParams{
		Managed: true,
		Country: "US",
	}

	acct, _ := New(params)

	tokenParams := &stripe.TokenParams{
		Card: &stripe.CardParams{
			Number:   "4000056655665556",
			Month:    "06",
			Year:     "20",
			Currency: "usd",
		},
	}

	tok, _ := token.New(tokenParams)

	cardParams := &stripe.CardParams{
		Account: acct.ID,
		Token:   tok.ID,
	}

	c, err := card.New(cardParams)

	if err != nil {
		t.Error(err)
	}

	if c.Currency != currency.USD {
		t.Errorf("Currency %v does not match expected value %v\n", c.Currency, currency.USD)
	}
}
コード例 #3
0
ファイル: client_test.go プロジェクト: captain401/stripe-go
func TestBankAccountListByCustomer(t *testing.T) {
	baTok, err := token.New(&stripe.TokenParams{
		Bank: &stripe.BankAccountParams{
			Country:           "US",
			Currency:          "usd",
			Routing:           "110000000",
			Account:           "000123456789",
			AccountHolderName: "Jane Austen",
			AccountHolderType: "individual",
		},
	})
	if err != nil {
		t.Error(err)
	}

	customerParams := &stripe.CustomerParams{}
	customerParams.SetSource(baTok.ID)
	cust, _ := customer.New(customerParams)
	if err != nil {
		t.Error(err)
	}

	iter := List(&stripe.BankAccountListParams{Customer: cust.ID})
	if iter.Err() != nil {
		t.Error(err)
	}
	if !iter.Next() {
		t.Errorf("Expected to find one bank account in list\n")
	}

	Del(cust.DefaultSource.ID, &stripe.BankAccountParams{Customer: cust.ID})
	customer.Del(cust.ID)
}
コード例 #4
0
ファイル: client_test.go プロジェクト: captain401/stripe-go
func TestBankAccountDel(t *testing.T) {
	baTok, err := token.New(&stripe.TokenParams{
		Bank: &stripe.BankAccountParams{
			Country:           "US",
			Currency:          "usd",
			Routing:           "110000000",
			Account:           "000123456789",
			AccountHolderName: "Jane Austen",
			AccountHolderType: "individual",
		},
	})
	if err != nil {
		t.Error(err)
	}

	customerParams := &stripe.CustomerParams{}
	customerParams.SetSource(baTok.ID)
	cust, _ := customer.New(customerParams)
	if err != nil {
		t.Error(err)
	}

	baDel, err := Del(cust.DefaultSource.ID, &stripe.BankAccountParams{Customer: cust.ID})
	if err != nil {
		t.Error(err)
	}

	if !baDel.Deleted {
		t.Errorf("Bank account id %q expected to be marked as deleted on the returned resource\n", baDel.ID)
	}

	customer.Del(cust.ID)
}
コード例 #5
0
ファイル: client_test.go プロジェクト: carriercomm/stripe-go
func TestAccountAddExternalAccountsDefault(t *testing.T) {
	params := &stripe.AccountParams{
		Managed: true,
		Country: "CA",
		ExternalAccount: &stripe.AccountExternalAccountParams{
			Country:  "US",
			Currency: "usd",
			Routing:  "110000000",
			Account:  "000123456789",
		},
	}

	acct, _ := New(params)

	ba, err := bankaccount.New(&stripe.BankAccountParams{
		AccountID: acct.ID,
		Country:   "US",
		Currency:  "usd",
		Routing:   "110000000",
		Account:   "000111111116",
		Default:   true,
	})

	if err != nil {
		t.Error(err)
	}

	if ba.Default == false {
		t.Error("The new external account should be the default but isn't.")
	}

	baTok, err := token.New(&stripe.TokenParams{
		Bank: &stripe.BankAccountParams{
			Country:  "US",
			Currency: "usd",
			Routing:  "110000000",
			Account:  "000333333335",
		},
	})
	if err != nil {
		t.Error(err)
	}

	ba2, err := bankaccount.New(&stripe.BankAccountParams{
		AccountID: acct.ID,
		Token:     baTok.ID,
		Default:   true,
	})

	if err != nil {
		t.Error(err)
	}

	if ba2.Default == false {
		t.Error("The third external account should be the default but isn't.")
	}
}
コード例 #6
0
ファイル: client_test.go プロジェクト: carriercomm/stripe-go
func TestSourceBankAccountVerify(t *testing.T) {
	baTok, err := token.New(&stripe.TokenParams{
		Bank: &stripe.BankAccountParams{
			Country:           "US",
			Currency:          "usd",
			Routing:           "110000000",
			Account:           "000123456789",
			AccountHolderName: "Jane Austen",
			AccountHolderType: "individual",
		},
	})

	if baTok.Bank.AccountHolderName != "Jane Austen" {
		t.Errorf("Bank account name %q was not Jane Austen as expected.", baTok.Bank.AccountHolderName)
	}

	if err != nil {
		t.Error(err)
	}

	customerParams := &stripe.CustomerParams{}
	cust, err := customer.New(customerParams)
	if err != nil {
		t.Error(err)
	}

	source, err := New(&stripe.CustomerSourceParams{
		Customer: cust.ID,
		Source: &stripe.SourceParams{
			Token: baTok.ID,
		},
	})

	amounts := [2]uint8{32, 45}

	verifyParams := &stripe.SourceVerifyParams{
		Customer: cust.ID,
		Amounts:  amounts,
	}

	sourceVerified, err := Verify(source.ID, verifyParams)

	if err != nil {
		t.Error(err)
		return
	}

	target := sourceVerified.BankAccount

	if target.Status != bankaccount.VerifiedAccount {
		t.Errorf("Status (%q) does not match expected (%q) ", target.Status, bankaccount.VerifiedAccount)
	}

	customer.Del(cust.ID)
}
コード例 #7
0
func withTestCreditCardToken(f func(token string)) {
	t, err := token.New(&stripe.TokenParams{
		Card: &stripe.CardParams{
			Number: "4242424242424242",
			Month:  "12",
			Year:   "2020",
			CVC:    "123",
		},
	})
	tests.ResultedWithNoErrorCheck(t, err)
	f(t.ID)
}
コード例 #8
0
ファイル: client_test.go プロジェクト: carriercomm/stripe-go
func TestSourceBankAccountDel(t *testing.T) {
	baTok, err := token.New(&stripe.TokenParams{
		Bank: &stripe.BankAccountParams{
			Country:           "US",
			Currency:          "usd",
			Routing:           "110000000",
			Account:           "000123456789",
			AccountHolderName: "Jane Austen",
			AccountHolderType: "individual",
		},
	})

	if baTok.Bank.AccountHolderName != "Jane Austen" {
		t.Errorf("Bank account name %q was not Jane Austen as expected.", baTok.Bank.AccountHolderName)
	}

	if err != nil {
		t.Error(err)
	}

	customerParams := &stripe.CustomerParams{}
	customer, err := customer.New(customerParams)
	if err != nil {
		t.Error(err)
	}

	source, err := New(&stripe.CustomerSourceParams{
		Customer: customer.ID,
		Source: &stripe.SourceParams{
			Token: baTok.ID,
		},
	})

	sourceDel, err := Del(source.ID, &stripe.CustomerSourceParams{Customer: customer.ID})

	if !sourceDel.Deleted {
		t.Errorf("Source id %q expected to be marked as deleted on the returned resource\n", sourceDel.ID)
	}
}
コード例 #9
0
ファイル: client_test.go プロジェクト: carriercomm/stripe-go
func TestSourceBankAccountGet(t *testing.T) {
	baTok, err := token.New(&stripe.TokenParams{
		Bank: &stripe.BankAccountParams{
			Country:           "US",
			Currency:          "usd",
			Routing:           "110000000",
			Account:           "000123456789",
			AccountHolderName: "Jane Austen",
			AccountHolderType: "individual",
		},
	})

	if baTok.Bank.AccountHolderName != "Jane Austen" {
		t.Errorf("Bank account token name %q was not Jane Austen as expected.", baTok.Bank.AccountHolderName)
	}

	if err != nil {
		t.Error(err)
	}

	customerParams := &stripe.CustomerParams{}
	customer, err := customer.New(customerParams)
	if err != nil {
		t.Error(err)
	}

	src, err := New(&stripe.CustomerSourceParams{
		Customer: customer.ID,
		Source: &stripe.SourceParams{
			Token: baTok.ID,
		},
	})

	source, err := Get(src.ID, &stripe.CustomerSourceParams{Customer: customer.ID})

	if source.BankAccount.AccountHolderName != "Jane Austen" {
		t.Errorf("Bank account name %q was not Jane Austen as expected.", source.BankAccount.Name)
	}
}
コード例 #10
0
ファイル: client_test.go プロジェクト: captain401/stripe-go
func TestBankAccountListByAccount(t *testing.T) {
	baTok, err := token.New(&stripe.TokenParams{
		Bank: &stripe.BankAccountParams{
			Country:           "US",
			Currency:          "usd",
			Routing:           "110000000",
			Account:           "000123456789",
			AccountHolderName: "Jane Austen",
			AccountHolderType: "individual",
		},
	})
	if err != nil {
		t.Error(err)
	}

	accountParams := &stripe.AccountParams{
		Managed: true,
		Country: "CA",
		ExternalAccount: &stripe.AccountExternalAccountParams{
			Token: baTok.ID,
		},
	}
	acct, err := account.New(accountParams)
	if err != nil {
		t.Error(err)
	}

	iter := List(&stripe.BankAccountListParams{AccountID: acct.ID})
	if iter.Err() != nil {
		t.Error(err)
	}
	if !iter.Next() {
		t.Errorf("Expected to find one bank account in list\n")
	}

	Del(baTok.ID, &stripe.BankAccountParams{AccountID: acct.ID})
	account.Del(acct.ID)
}
コード例 #11
0
ファイル: client_test.go プロジェクト: mousadialo/stripe-go
func TestChargeNewWithToken(t *testing.T) {
	tokenParams := &stripe.TokenParams{
		Card: &stripe.CardParams{
			Number: "4242424242424242",
			Month:  "10",
			Year:   "20",
		},
	}

	tok, _ := token.New(tokenParams)

	chargeParams := &stripe.ChargeParams{
		Amount:   1000,
		Currency: currency.USD,
	}

	chargeParams.SetSource(tok.ID)

	target, err := New(chargeParams)

	if err != nil {
		t.Error(err)
	}

	if target.Amount != chargeParams.Amount {
		t.Errorf("Amount %v does not match expected amount %v\n", target.Amount, chargeParams.Amount)
	}

	if target.Currency != chargeParams.Currency {
		t.Errorf("Currency %q does not match expected currency %q\n", target.Currency, chargeParams.Currency)
	}

	if target.Source.Card.ID != tok.Card.ID {
		t.Errorf("Card Id %q doesn't match card id %q of token %q", target.Source.Card.ID, tok.Card.ID, tok.ID)
	}
}
コード例 #12
0
ファイル: client_test.go プロジェクト: captain401/stripe-go
func TestCardNew(t *testing.T) {
	customerParams := &stripe.CustomerParams{}
	customerParams.SetSource(&stripe.CardParams{
		Number: "378282246310005",
		Month:  "06",
		Year:   "20",
	})

	cust, _ := customer.New(customerParams)

	cardParams := &stripe.CardParams{
		Number:   "4242424242424242",
		Month:    "10",
		Year:     "20",
		Customer: cust.ID,
		CVC:      "1234",
	}

	target, err := New(cardParams)

	if err != nil {
		t.Error(err)
	}

	if target.LastFour != "4242" {
		t.Errorf("Unexpected last four %q for card number %v\n", target.LastFour, cardParams.Number)
	}

	if target.Meta == nil || len(target.Meta) > 0 {
		t.Errorf("Unexpected nil or non-empty metadata in card\n")
	}

	if target.Month != 10 {
		t.Errorf("Unexpected expiration month %d for card where we set %q\n", target.Month, cardParams.Month)
	}

	if target.Year != 2020 {
		t.Errorf("Unexpected expiration year %d for card where we set %q\n", target.Year, cardParams.Year)
	}

	if target.CVCCheck != Pass {
		t.Errorf("CVC check %q does not match expected status\n", target.ZipCheck)
	}

	targetCust, err := customer.Get(cust.ID, nil)

	if err != nil {
		t.Error(err)
	}

	if targetCust.Sources.Count != 2 {
		t.Errorf("Unexpected number of sources %v\n", targetCust.Sources.Count)
	}

	targetToken, err := token.New(&stripe.TokenParams{
		Card: &stripe.CardParams{
			Number: "4000056655665556",
			Month:  "09",
			Year:   "2021",
			CVC:    "123",
		},
	})

	targetCard, err := New(&stripe.CardParams{
		Customer: targetCust.ID,
		Token:    targetToken.ID,
	})

	if targetCard.LastFour != "5556" {
		t.Errorf("Unexpected last four %q for card number %v\n", targetCard.LastFour, cardParams.Number)
	}

	if targetCard.Month != 9 {
		t.Errorf("Unexpected expiration month %d for card where we set %q\n", targetCard.Month, targetToken.Card.Month)
	}

	if targetCard.Year != 2021 {
		t.Errorf("Unexpected expiration year %d for card where we set %q\n", targetCard.Year, targetToken.Card.Year)
	}

	customer.Del(cust.ID)
}
コード例 #13
0
ファイル: client_test.go プロジェクト: mousadialo/stripe-go
func TestRecipientNewToken(t *testing.T) {

	tokenParams := &stripe.TokenParams{
		Bank: &stripe.BankAccountParams{
			Country: "US",
			Routing: "110000000",
			Account: "000123456789",
		},
	}

	tok, _ := token.New(tokenParams)

	recipientParams := &stripe.RecipientParams{
		Name:  "Recipient Name",
		Type:  Individual,
		TaxID: "000000000",
		Email: "*****@*****.**",
		Desc:  "Recipient Desc",
		Bank: &stripe.BankAccountParams{
			Token: tok.ID,
		},
		Card: &stripe.CardParams{
			Name:   "Test Debit",
			Number: "4000056655665556",
			Month:  "10",
			Year:   "20",
		},
	}

	target, err := New(recipientParams)

	if err != nil {
		t.Error(err)
	}

	if target.Name != recipientParams.Name {
		t.Errorf("Name %q does not match expected name %q\n", target.Name, recipientParams.Name)
	}

	if target.Type != recipientParams.Type {
		t.Errorf("Type %q does not match expected type %q\n", target.Type, recipientParams.Type)
	}

	if target.Email != recipientParams.Email {
		t.Errorf("Email %q does not match expected email %q\n", target.Email, recipientParams.Email)
	}

	if target.Desc != recipientParams.Desc {
		t.Errorf("Description %q does not match expected description %q\n", target.Desc, recipientParams.Desc)
	}

	if target.Created == 0 {
		t.Errorf("Created date is not set\n")
	}

	if target.Bank == nil {
		t.Errorf("Bank account is not set\n")
	}

	if target.Bank.Country != tokenParams.Bank.Country {
		t.Errorf("Bank country %q does not match expected country %q\n", target.Bank.Country, tokenParams.Bank.Country)
	}

	if target.Bank.Currency != currency.USD {
		t.Errorf("Bank currency %q does not match expected value\n", target.Bank.Currency)
	}

	if target.Bank.LastFour != "6789" {
		t.Errorf("Bank last four %q does not match expected value\n", target.Bank.LastFour)
	}

	if len(target.Bank.Name) == 0 {
		t.Errorf("Bank name is not set\n")
	}

	if target.Cards == nil || target.Cards.Count != 1 {
		t.Errorf("Recipient cards not set\n")
	}

	if len(target.DefaultCard.ID) == 0 {
		t.Errorf("Recipient default card is not set\n")
	}

	Del(target.ID)
}
コード例 #14
0
ファイル: client_test.go プロジェクト: carriercomm/stripe-go
func TestRecipientUpdateBankAccount(t *testing.T) {
	tokenParams := &stripe.TokenParams{
		Bank: &stripe.BankAccountParams{
			Country: "US",
			Routing: "110000000",
			Account: "000123456789",
		},
	}

	tok, _ := token.New(tokenParams)

	recipientParams := &stripe.RecipientParams{
		Name:  "Original Name",
		Type:  Individual,
		Email: "*****@*****.**",
		Desc:  "Original Desc",
	}

	original, _ := New(recipientParams)

	updateParamsToken := &stripe.RecipientParams{
		Bank: &stripe.BankAccountParams{
			Token: tok.ID,
		},
	}

	target, err := Update(original.ID, updateParamsToken)

	if err != nil {
		t.Error(err)
	}

	if target.Bank == nil {
		t.Errorf("Bank account is not set\n")
	}

	if target.Bank.Country != tokenParams.Bank.Country {
		t.Errorf("Bank country %q does not match expected country %q\n", target.Bank.Country, tokenParams.Bank.Country)
	}

	if target.Bank.Currency != currency.USD {
		t.Errorf("Bank currency %q does not match expected value\n", target.Bank.Currency)
	}

	if target.Bank.LastFour != "6789" {
		t.Errorf("Bank last four %q does not match expected value\n", target.Bank.LastFour)
	}

	if len(target.Bank.Name) == 0 {
		t.Errorf("Bank name is not set\n")
	}

	updateParamsBankAccount := &stripe.RecipientParams{
		Bank: &stripe.BankAccountParams{
			Country: "US",
			Routing: "110000000",
			Account: "000333333335",
		},
	}

	target2, err := Update(original.ID, updateParamsBankAccount)

	if err != nil {
		t.Error(err)
	}

	if target2.Bank == nil {
		t.Errorf("Bank account is not set\n")
	}

	if target2.Bank.Country != tokenParams.Bank.Country {
		t.Errorf("Bank country %q does not match expected country %q\n", target2.Bank.Country, tokenParams.Bank.Country)
	}

	if target2.Bank.Currency != currency.USD {
		t.Errorf("Bank currency %q does not match expected value\n", target2.Bank.Currency)
	}

	if target2.Bank.LastFour != "3335" {
		t.Errorf("Bank last four %q does not match expected value\n", target2.Bank.LastFour)
	}

	if len(target2.Bank.Name) == 0 {
		t.Errorf("Bank name is not set\n")
	}

	Del(target2.ID)
}