本文整理汇总了Golang中github.com/stripe/stripe-go/customer.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestCardUpdate
func TestCardUpdate(t *testing.T) {
customerParams := &stripe.CustomerParams{}
customerParams.SetSource(&stripe.CardParams{
Number: "378282246310005",
Month: "06",
Year: "20",
Name: "Original Name",
})
cust, err := customer.New(customerParams)
if err != nil {
t.Error(err)
}
cardParams := &stripe.CardParams{
Customer: cust.ID,
Name: "Updated Name",
}
target, err := Update(cust.DefaultSource.ID, cardParams)
if err != nil {
t.Error(err)
}
if target.Name != cardParams.Name {
t.Errorf("Card name %q does not match expected name %q\n", target.Name, cardParams.Name)
}
customer.Del(cust.ID)
}
示例2: TestSourceCardGet
func TestSourceCardGet(t *testing.T) {
customerParams := &stripe.CustomerParams{
Email: "[email protected]",
}
customerParams.SetSource(&stripe.CardParams{
Number: "4242424242424242",
Month: "06",
Year: "20",
})
cust, err := customer.New(customerParams)
if err != nil {
t.Error(err)
}
source, err := Get(cust.DefaultSource.ID, &stripe.CustomerSourceParams{Customer: cust.ID})
if err != nil {
t.Error(err)
}
target := source.Card
if target.LastFour != "4242" {
t.Errorf("Unexpected last four %q for card number %v\n", target.LastFour, customerParams.Source.Card.Number)
}
if target.Brand != card.Visa {
t.Errorf("Card brand %q does not match expected value\n", target.Brand)
}
customer.Del(cust.ID)
}
示例3: TestBankAccountDel
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)
}
示例4: TestBankAccountListByCustomer
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)
}
示例5: TestCardList
func TestCardList(t *testing.T) {
customerParams := &stripe.CustomerParams{}
customerParams.SetSource(&stripe.CardParams{
Number: "378282246310005",
Month: "06",
Year: "20",
})
cust, _ := customer.New(customerParams)
card := &stripe.CardParams{
Number: "4242424242424242",
Month: "10",
Year: "20",
Customer: cust.ID,
}
New(card)
i := List(&stripe.CardListParams{Customer: cust.ID})
for i.Next() {
if i.Card() == nil {
t.Error("No nil values expected")
}
if i.Meta() == nil {
t.Error("No metadata returned")
}
}
if err := i.Err(); err != nil {
t.Error(err)
}
customer.Del(cust.ID)
}
示例6: TestSubscriptionNew
func TestSubscriptionNew(t *testing.T) {
customerParams := &stripe.CustomerParams{
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "378282246310005",
Month: "06",
Year: "20",
},
},
}
cust, _ := customer.New(customerParams)
planParams := &stripe.PlanParams{
ID: "test",
Name: "Test Plan",
Amount: 99,
Currency: currency.USD,
Interval: plan.Month,
}
plan.New(planParams)
subParams := &stripe.SubParams{
Customer: cust.ID,
Plan: "test",
Quantity: 10,
TaxPercent: 20.0,
BillingCycleAnchor: time.Now().AddDate(0, 0, 12).Unix(),
}
target, err := New(subParams)
if err != nil {
t.Error(err)
}
if target.Plan.ID != subParams.Plan {
t.Errorf("Plan %v does not match expected plan %v\n", target.Plan, subParams.Plan)
}
if target.Quantity != subParams.Quantity {
t.Errorf("Quantity %v does not match expected quantity %v\n", target.Quantity, subParams.Quantity)
}
if target.TaxPercent != subParams.TaxPercent {
t.Errorf("TaxPercent %f does not match expected TaxPercent %f\n", target.TaxPercent, subParams.TaxPercent)
}
if target.PeriodEnd != subParams.BillingCycleAnchor {
t.Errorf("PeriodEnd %v does not match expected BillingCycleAnchor %v\n", target.PeriodEnd, subParams.BillingCycleAnchor)
}
customer.Del(cust.ID)
plan.Del("test")
}
示例7: createSubItem
func createSubItem(t *testing.T) (*stripe.Sub, *stripe.SubItem, func()) {
customerParams := &stripe.CustomerParams{
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "378282246310005",
Month: "06",
Year: "20",
},
},
}
cust, err := customer.New(customerParams)
if err != nil {
t.Fatalf("customer creation: %s", err)
}
planID := fmt.Sprintf("test-%d", rand.Int63())
planParams := &stripe.PlanParams{
ID: planID,
Name: "Test Plan",
Amount: 99,
Currency: currency.USD,
Interval: plan.Month,
}
p, err := plan.New(planParams)
if err != nil {
t.Fatalf("plan creation: %s", err)
}
subParams := &stripe.SubParams{
Customer: cust.ID,
Items: []*stripe.SubItemsParams{
{
Plan: p.ID,
Quantity: 1,
},
},
}
target, err := sub.New(subParams)
if err != nil {
t.Fatalf("subscription creation: %s", err)
}
if target.Items == nil {
t.Fatalf("no items for sub %s", target.ID)
}
if len(target.Items.Values) != 1 {
t.Fatalf("missing items: %#v", target)
}
return target, target.Items.Values[0], func() {
sub.Cancel(target.ID, nil)
plan.Del(p.ID)
customer.Del(cust.ID)
}
}
示例8: TestSourceBankAccountVerify
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)
}
示例9: TestSubscriptionUpdate
func TestSubscriptionUpdate(t *testing.T) {
customerParams := &stripe.CustomerParams{
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "378282246310005",
Month: "06",
Year: "20",
},
},
}
cust, _ := customer.New(customerParams)
planParams := &stripe.PlanParams{
ID: "test",
Name: "Test Plan",
Amount: 99,
Currency: currency.USD,
Interval: plan.Month,
}
plan.New(planParams)
subParams := &stripe.SubParams{
Customer: cust.ID,
Plan: "test",
Quantity: 10,
TrialEndNow: true,
}
subscription, _ := New(subParams)
updatedSub := &stripe.SubParams{
Customer: cust.ID,
NoProrate: true,
Quantity: 13,
TaxPercent: 20.0,
}
target, err := Update(subscription.ID, updatedSub)
if err != nil {
t.Error(err)
}
if target.Quantity != updatedSub.Quantity {
t.Errorf("Quantity %v does not match expected quantity %v\n", target.Quantity, updatedSub.Quantity)
}
if target.TaxPercent != updatedSub.TaxPercent {
t.Errorf("TaxPercent %f does not match expected tax_percent %f\n", target.TaxPercent, updatedSub.TaxPercent)
}
customer.Del(cust.ID)
plan.Del("test")
}
示例10: TestSubscriptionCancel
func TestSubscriptionCancel(t *testing.T) {
customerParams := &stripe.CustomerParams{
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "378282246310005",
Month: "06",
Year: "20",
},
},
}
cust, _ := customer.New(customerParams)
planParams := &stripe.PlanParams{
ID: "test",
Name: "Test Plan",
Amount: 99,
Currency: currency.USD,
Interval: plan.Month,
}
plan.New(planParams)
subParams := &stripe.SubParams{
Customer: cust.ID,
Plan: "test",
Quantity: 10,
}
subscription, _ := New(subParams)
s, err := Cancel(subscription.ID, nil)
if err != nil {
t.Error(err)
}
if s.Canceled == 0 {
t.Errorf("Subscription.Canceled %v expected to be non 0\n", s.Canceled)
}
subscription, _ = New(subParams)
s, err = Cancel(subscription.ID, &stripe.SubParams{Customer: cust.ID})
if err != nil {
t.Error(err)
}
if s.Canceled == 0 {
t.Errorf("Subscription.Canceled %v expected to be non 0\n", s.Canceled)
}
customer.Del(cust.ID)
plan.Del("test")
}
示例11: TestSubscriptionGet
func TestSubscriptionGet(t *testing.T) {
customerParams := &stripe.CustomerParams{
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "378282246310005",
Month: "06",
Year: "20",
},
},
}
cust, _ := customer.New(customerParams)
planParams := &stripe.PlanParams{
ID: "test",
Name: "Test Plan",
Amount: 99,
Currency: currency.USD,
Interval: plan.Month,
}
plan.New(planParams)
subParams := &stripe.SubParams{
Customer: cust.ID,
Plan: "test",
Quantity: 10,
}
subscription, _ := New(subParams)
target, err := Get(subscription.ID, nil)
if err != nil {
t.Error(err)
}
if target.ID != subscription.ID {
t.Errorf("Subscription id %q does not match expected id %q\n", target.ID, subscription.ID)
}
target, err = Get(subscription.ID, &stripe.SubParams{Customer: cust.ID})
if err != nil {
t.Error(err)
}
if target.ID != subscription.ID {
t.Errorf("Subscription id %q does not match expected id %q\n", target.ID, subscription.ID)
}
customer.Del(cust.ID)
plan.Del("test")
}
示例12: TestSubscriptionZeroQuantity
func TestSubscriptionZeroQuantity(t *testing.T) {
customerParams := &stripe.CustomerParams{
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "378282246310005",
Month: "06",
Year: "20",
},
},
}
cust, _ := customer.New(customerParams)
planParams := &stripe.PlanParams{
ID: "test",
Name: "Test Plan",
Amount: 99,
Currency: currency.USD,
Interval: plan.Month,
}
plan.New(planParams)
subParams := &stripe.SubParams{
Customer: cust.ID,
Plan: "test",
QuantityZero: true,
TaxPercentZero: true,
}
target, err := New(subParams)
if err != nil {
t.Error(err)
}
if target.Plan.ID != subParams.Plan {
t.Errorf("Plan %v does not match expected plan %v\n", target.Plan, subParams.Plan)
}
if target.Quantity != 0 {
t.Errorf("Quantity %v does not match expected quantity %v\n", target.Quantity, 0)
}
if target.TaxPercent != 0 {
t.Errorf("Tax percent %v does not match expected tax percent %v\n", target.TaxPercent, 0)
}
customer.Del(cust.ID)
plan.Del("test")
}
示例13: TestSubscriptionList
func TestSubscriptionList(t *testing.T) {
customerParams := &stripe.CustomerParams{
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "378282246310005",
Month: "06",
Year: "20",
},
},
}
cust, _ := customer.New(customerParams)
planParams := &stripe.PlanParams{
ID: "test",
Name: "Test Plan",
Amount: 99,
Currency: currency.USD,
Interval: plan.Month,
}
plan.New(planParams)
subParams := &stripe.SubParams{
Customer: cust.ID,
Plan: "test",
Quantity: 10,
}
for i := 0; i < 5; i++ {
New(subParams)
}
i := List(&stripe.SubListParams{Customer: cust.ID})
for i.Next() {
if i.Sub() == nil {
t.Error("No nil values expected")
}
if i.Meta() == nil {
t.Error("No metadata returned")
}
}
if err := i.Err(); err != nil {
t.Error(err)
}
customer.Del(cust.ID)
plan.Del("test")
}
示例14: TestThreeDSecureNew
func TestThreeDSecureNew(t *testing.T) {
// Test creating a 3D Secure auth
customerParams := &stripe.CustomerParams{}
customerParams.SetSource(&stripe.CardParams{
Name: "Stripe Tester",
Number: "378282246310005",
Month: "06",
Year: "20",
})
cust, _ := customer.New(customerParams)
threeDSecureParams := &stripe.ThreeDSecureParams{
Amount: 1000,
Currency: currency.USD,
Customer: cust.ID,
Card: cust.Sources.Values[0].Card.ID,
ReturnURL: "https://test.com",
}
threeDSecure, err := New(threeDSecureParams)
if err != nil {
t.Error(err)
}
if threeDSecure.Amount != threeDSecureParams.Amount {
t.Errorf("Amount %v does not match expected amount %v\n", threeDSecure.Amount, threeDSecureParams.Amount)
}
if threeDSecure.Currency != threeDSecureParams.Currency {
t.Errorf("Currency %q does not match expected currency %q\n", threeDSecure.Currency, threeDSecureParams.Currency)
}
if threeDSecure.Card.ID != threeDSecureParams.Card {
t.Errorf("Card ID %q does not match expected card ID %q\n", threeDSecure.Card.ID, threeDSecureParams.Card)
}
// Test retrieving a 3D Secure auth
threeDSecure2, err := Get(threeDSecure.ID, nil)
if err != nil {
t.Error(err)
}
if threeDSecure2.ID != threeDSecure.ID {
t.Errorf("ID %q does not match expected id %q\n", threeDSecure2.ID, threeDSecure.ID)
}
}
示例15: TestSourceVerify
func TestSourceVerify(t *testing.T) {
bankAccountParams := &stripe.BankAccountParams{
Country: "US",
Currency: "usd",
Routing: "110000000",
Account: "000123456789",
}
tokenParams := &stripe.TokenParams{
Bank: bankAccountParams,
}
token, err := token.New(tokenParams)
if err != nil {
t.Error(err)
return
}
customerParams := &stripe.CustomerParams{}
customerParams.SetSource(token.ID)
cust, err := customer.New(customerParams)
if err != nil {
t.Error(err)
return
}
amounts := [2]uint8{32, 45}
verifyParams := &stripe.SourceVerifyParams{
Customer: cust.ID,
Amounts: amounts,
}
source, err := Verify(cust.DefaultSource.ID, verifyParams)
if err != nil {
t.Error(err)
return
}
target := source.BankAccount
if target.Status != bankaccount.VerifiedAccount {
t.Errorf("Status (%q) does not match expected (%q) ", target.Status, bankaccount.VerifiedAccount)
}
customer.Del(cust.ID)
}