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

     1  package stripe_test
     2  
     3  import (
     4  	"log"
     5  
     6  	stripe "github.com/stripe/stripe-go/v76"
     7  	"github.com/stripe/stripe-go/v76/charge"
     8  	"github.com/stripe/stripe-go/v76/customer"
     9  	"github.com/stripe/stripe-go/v76/invoice"
    10  	"github.com/stripe/stripe-go/v76/plan"
    11  )
    12  
    13  func ExampleCharge_new() {
    14  	stripe.Key = "sk_key"
    15  
    16  	params := &stripe.ChargeParams{
    17  		Amount:   stripe.Int64(1000),
    18  		Currency: stripe.String(string(stripe.CurrencyUSD)),
    19  	}
    20  	params.SetSource("tok_visa")
    21  	params.AddMetadata("key", "value")
    22  
    23  	ch, err := charge.New(params)
    24  
    25  	if err != nil {
    26  		log.Fatal(err)
    27  	}
    28  
    29  	log.Printf("%v\n", ch.ID)
    30  }
    31  
    32  func ExampleCharge_get() {
    33  	stripe.Key = "sk_key"
    34  
    35  	params := &stripe.ChargeParams{}
    36  	params.AddExpand("customer")
    37  	params.AddExpand("application")
    38  	params.AddExpand("balance_transaction")
    39  
    40  	ch, err := charge.Get("ch_example_id", params)
    41  
    42  	if err != nil {
    43  		log.Fatal(err)
    44  	}
    45  
    46  	if ch.Application != nil {
    47  		log.Fatal(err)
    48  	}
    49  
    50  	log.Printf("%v\n", ch.ID)
    51  }
    52  
    53  func ExampleInvoice_update() {
    54  	stripe.Key = "sk_key"
    55  
    56  	params := &stripe.InvoiceParams{
    57  		Description: stripe.String("updated description"),
    58  	}
    59  
    60  	inv, err := invoice.Update("sub_example_id", params)
    61  
    62  	if err != nil {
    63  		log.Fatal(err)
    64  	}
    65  
    66  	log.Printf("%v\n", inv.Description)
    67  }
    68  
    69  func ExampleCustomer_delete() {
    70  	stripe.Key = "sk_key"
    71  
    72  	customerDel, err := customer.Del("cus_example_id", nil)
    73  
    74  	if err != nil {
    75  		log.Fatal(err)
    76  	}
    77  
    78  	if !customerDel.Deleted {
    79  		log.Fatal("Customer doesn't appear deleted while it should be")
    80  	}
    81  }
    82  
    83  func ExamplePlan_list() {
    84  	stripe.Key = "sk_key"
    85  
    86  	params := &stripe.PlanListParams{}
    87  	params.Filters.AddFilter("limit", "", "3")
    88  	params.Single = true
    89  
    90  	it := plan.List(params)
    91  	for it.Next() {
    92  		log.Printf("%v ", it.Plan().Nickname)
    93  	}
    94  	if err := it.Err(); err != nil {
    95  		log.Fatal(err)
    96  	}
    97  }