本文整理汇总了Golang中github.com/stripe/stripe-go/charge.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestRefundGet
func TestRefundGet(t *testing.T) {
chargeParams := &stripe.ChargeParams{
Amount: 1000,
Currency: currency.USD,
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "378282246310005",
Month: "06",
Year: "20",
},
},
}
ch, err := charge.New(chargeParams)
if err != nil {
t.Error(err)
}
ref, err := New(&stripe.RefundParams{Charge: ch.ID})
if err != nil {
t.Error(err)
}
target, err := Get(ref.ID, &stripe.RefundParams{Charge: ch.ID})
if err != nil {
t.Error(err)
}
if target.Charge != ch.ID {
t.Errorf("Refund charge %q does not match expected value %v\n", target.Charge, ch.ID)
}
}
开发者ID:carriercomm,项目名称:stripe-go,代码行数:35,代码来源:client_test.go
示例2: chargeAccount
func chargeAccount(ctx context.Context, stripeToken string) error {
// because we're on app engine, use a custom http client
// this is being set globally, however
// if we wanted to do it this way, we'd have to use a lock
// https://youtu.be/KT4ki_ClX2A?t=1018
hc := urlfetch.Client(ctx)
stripe.SetHTTPClient(hc)
id, _ := uuid.NewV4()
for {
chargeParams := &stripe.ChargeParams{
Amount: 100 * 200000,
Currency: "usd",
Desc: "Charge for [email protected]",
}
chargeParams.IdempotencyKey = id.String()
chargeParams.SetSource(stripeToken)
ch, err := charge.New(chargeParams)
// https://youtu.be/KT4ki_ClX2A?t=1310
if err != nil {
if nerr, ok := err.(net.Error); ok && nerr.Temporary() {
time.Sleep(time.Second)
continue
}
return err
}
log.Infof(ctx, "CHARGE: %v", ch)
log.Infof(ctx, "IDEMPOTENCY: %v", chargeParams.IdempotencyKey)
return nil
}
}
开发者ID:RobertoSuarez,项目名称:GolangTraining,代码行数:32,代码来源:stripe.go
示例3: newDisputedCharge
func newDisputedCharge() (*stripe.Charge, error) {
chargeParams := &stripe.ChargeParams{
Amount: 1001,
Currency: currency.USD,
}
chargeParams.SetSource(&stripe.CardParams{
Number: "4000000000000259",
Month: "06",
Year: "20",
})
res, err := charge.New(chargeParams)
if err != nil {
return nil, err
}
target, err := charge.Get(res.ID, nil)
if err != nil {
return target, err
}
for target.Dispute == nil {
time.Sleep(time.Second * 10)
target, err = charge.Get(res.ID, nil)
if err != nil {
return target, err
}
}
return target, err
}
开发者ID:mousadialo,项目名称:stripe-go,代码行数:32,代码来源:client_test.go
示例4: buyPrint
func buyPrint(responseWriter http.ResponseWriter, request *http.Request, requestParameters httprouter.Params) {
successMessage := validBuyPrintPostVariables(request)
if !successMessage.Success {
json.NewEncoder(responseWriter).Encode(successMessage)
return
}
buyPrintToken := request.PostFormValue("buy-print-token")
costInCents := printCostInCents[request.PostFormValue("print-size")]
if credentials.LiveOrDev == "live" {
stripe.Key = credentials.StripeLiveSecretKey
} else {
stripe.Key = credentials.StripeTestSecretKey
}
chargeParams := &stripe.ChargeParams{
Amount: costInCents,
Currency: "usd",
Desc: request.PostFormValue("shipping-email") + " " + request.PostFormValue("destination-link"),
}
chargeParams.SetSource(buyPrintToken)
chargeResults, error := charge.New(chargeParams)
if error != nil {
successMessage.SetMessage(false, error.Error())
json.NewEncoder(responseWriter).Encode(successMessage)
return
}
json.NewEncoder(responseWriter).Encode(successMessage)
sendBuyPrintSuccessEmail(request, chargeResults.ID)
}
开发者ID:spyrosoft,项目名称:firefractal.com,代码行数:28,代码来源:buy-print.go
示例5: TestTransferList
func TestTransferList(t *testing.T) {
chargeParams := &stripe.ChargeParams{
Amount: 1000,
Currency: currency.USD,
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "4000000000000077",
Month: "06",
Year: "20",
},
},
}
charge.New(chargeParams)
recipientParams := &stripe.RecipientParams{
Name: "Recipient Name",
Type: recipient.Individual,
Card: &stripe.CardParams{
Name: "Test Debit",
Number: "4000056655665556",
Month: "10",
Year: "20",
},
}
rec, _ := recipient.New(recipientParams)
transferParams := &stripe.TransferParams{
Amount: 100,
Currency: currency.USD,
Recipient: rec.ID,
}
for i := 0; i < 5; i++ {
New(transferParams)
}
i := List(&stripe.TransferListParams{Recipient: rec.ID})
for i.Next() {
if i.Transfer() == 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)
}
recipient.Del(rec.ID)
}
开发者ID:captain401,项目名称:stripe-go,代码行数:54,代码来源:client_test.go
示例6: TestTransferUpdate
func TestTransferUpdate(t *testing.T) {
chargeParams := &stripe.ChargeParams{
Amount: 1000,
Currency: currency.USD,
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "4000000000000077",
Month: "06",
Year: "20",
},
},
}
charge.New(chargeParams)
recipientParams := &stripe.RecipientParams{
Name: "Recipient Name",
Type: recipient.Corp,
Bank: &stripe.BankAccountParams{
Country: "US",
Routing: "110000000",
Account: "000123456789",
},
}
rec, _ := recipient.New(recipientParams)
transferParams := &stripe.TransferParams{
Amount: 100,
Currency: currency.USD,
Recipient: rec.ID,
Desc: "Original",
}
trans, _ := New(transferParams)
updated := &stripe.TransferParams{
Desc: "Updated",
}
target, err := Update(trans.ID, updated)
if err != nil {
t.Error(err)
}
if target.Desc != updated.Desc {
t.Errorf("Description %q does not match expected description %q\n", target.Desc, updated.Desc)
}
recipient.Del(rec.ID)
}
开发者ID:captain401,项目名称:stripe-go,代码行数:52,代码来源:client_test.go
示例7: TestTransferGet
func TestTransferGet(t *testing.T) {
chargeParams := &stripe.ChargeParams{
Amount: 1000,
Currency: currency.USD,
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "4000000000000077",
Month: "06",
Year: "20",
},
},
}
charge.New(chargeParams)
recipientParams := &stripe.RecipientParams{
Name: "Recipient Name",
Type: recipient.Individual,
Card: &stripe.CardParams{
Name: "Test Debit",
Number: "4000056655665556",
Month: "10",
Year: "20",
},
}
rec, _ := recipient.New(recipientParams)
transferParams := &stripe.TransferParams{
Amount: 100,
Currency: currency.USD,
Recipient: rec.ID,
}
trans, _ := New(transferParams)
target, err := Get(trans.ID, nil)
if err != nil {
t.Error(err)
}
if target.Card == nil {
t.Errorf("Card is not set\n")
}
if target.Type != Card {
t.Errorf("Unexpected type %q\n", target.Type)
}
recipient.Del(rec.ID)
}
开发者ID:captain401,项目名称:stripe-go,代码行数:52,代码来源:client_test.go
示例8: TestTransferSourceType
func TestTransferSourceType(t *testing.T) {
chargeParams := &stripe.ChargeParams{
Amount: 1000,
Currency: currency.USD,
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "4000000000000077",
Month: "06",
Year: "20",
},
},
}
_, err := charge.New(chargeParams)
if err != nil {
t.Error(err)
}
transferParams := &stripe.TransferParams{
Amount: 100,
Currency: currency.USD,
Dest: "default_for_currency",
SourceType: SourceCard,
}
target, err := New(transferParams)
if err != nil {
t.Error(err)
}
if target.Amount != transferParams.Amount {
t.Errorf("Amount %v does not match expected amount %v\n", target.Amount, transferParams.Amount)
}
if target.Currency != transferParams.Currency {
t.Errorf("Curency %q does not match expected currency %q\n", target.Currency, transferParams.Currency)
}
if target.Created == 0 {
t.Errorf("Created date is not set\n")
}
if target.Date == 0 {
t.Errorf("Date is not set\n")
}
if target.Type != Bank {
t.Errorf("Unexpected type %q\n", target.Type)
}
}
开发者ID:captain401,项目名称:stripe-go,代码行数:51,代码来源:client_test.go
示例9: chargeAccount
func chargeAccount(ctx context.Context, stripeToken string) error {
chargeParams := &stripe.ChargeParams{
Amount: 100 * 200000,
Currency: "usd",
Desc: "Charge for [email protected]",
}
chargeParams.SetSource(stripeToken)
ch, err := charge.New(chargeParams)
if err != nil {
return err
}
log.Infof(ctx, "CHARGE: %v", ch)
return nil
}
开发者ID:RaviTezu,项目名称:GolangTraining,代码行数:14,代码来源:stripe.go
示例10: TestRefundListByCharge
func TestRefundListByCharge(t *testing.T) {
chargeParams := &stripe.ChargeParams{
Amount: 1000,
Currency: currency.USD,
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "378282246310005",
Month: "06",
Year: "20",
},
},
}
ch, err := charge.New(chargeParams)
if err != nil {
t.Error(err)
}
for i := 0; i < 4; i++ {
_, err = New(&stripe.RefundParams{Charge: ch.ID, Amount: 200})
if err != nil {
t.Error(err)
}
}
listParams := &stripe.RefundListParams{}
listParams.Filters.AddFilter("charge", "", ch.ID)
i := List(listParams)
for i.Next() {
target := i.Refund()
if target.Amount != 200 {
t.Errorf("Amount %v does not match expected value\n", target.Amount)
}
if target.Charge != ch.ID {
t.Errorf("Refund charge %q does not match expected value %q\n", target.Charge, ch.ID)
}
if i.Meta() == nil {
t.Error("No metadata returned")
}
}
if err := i.Err(); err != nil {
t.Error(err)
}
}
开发者ID:carriercomm,项目名称:stripe-go,代码行数:49,代码来源:client_test.go
示例11: TestReversalGet
func TestReversalGet(t *testing.T) {
chargeParams := &stripe.ChargeParams{
Amount: 1000,
Currency: currency.USD,
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "4000000000000077",
Month: "06",
Year: "20",
},
},
}
charge.New(chargeParams)
recipientParams := &stripe.RecipientParams{
Name: "Recipient Name",
Type: recipient.Individual,
Bank: &stripe.BankAccountParams{
Country: "US",
Routing: "110000000",
Account: "000123456789",
},
}
rec, _ := recipient.New(recipientParams)
transferParams := &stripe.TransferParams{
Amount: 100,
Currency: currency.USD,
Recipient: rec.ID,
Desc: "Transfer Desc",
Statement: "Transfer",
}
trans, _ := transfer.New(transferParams)
rev, _ := New(&stripe.ReversalParams{Transfer: trans.ID})
target, err := Get(rev.ID, &stripe.ReversalParams{Transfer: trans.ID})
if err != nil {
// TODO: replace this with t.Error when this can be tested
fmt.Println(err)
}
fmt.Printf("%+v\n", target)
}
开发者ID:mousadialo,项目名称:stripe-go,代码行数:47,代码来源:client_test.go
示例12: ExampleCharge_new
func ExampleCharge_new() {
stripe.Key = "sk_key"
params := &stripe.ChargeParams{
Amount: 1000,
Currency: currency.USD,
}
params.SetSource(&stripe.CardParams{
Name: "Go Stripe",
Number: "4242424242424242",
Month: "10",
Year: "20",
})
params.AddMeta("key", "value")
ch, err := charge.New(params)
if err != nil {
log.Fatal(err)
}
log.Printf("%v\n", ch.ID)
}
开发者ID:yoyowallet,项目名称:stripe-go,代码行数:23,代码来源:example_test.go
示例13: createDebit
func createDebit(token string, amount uint64, description string) *stripe.Charge {
// get your secret test key from
// https://dashboard.stripe.com/account/apikeys and place it here
stripe.Key = "sk_test_goes_here"
params := &stripe.ChargeParams{
Amount: amount,
Currency: currency.USD,
Desc: "test charge",
}
// obtain token from stripe
params.SetSource(token)
ch, err := charge.New(params)
if err != nil {
log.Fatalf("error while trying to charge a cc", err)
}
log.Printf("debit created successfully %v\n", ch.ID)
return ch
}
开发者ID:lrudolph1,项目名称:stripe-demo-golang,代码行数:24,代码来源:main.go
示例14: TestTransferToAccount
func TestTransferToAccount(t *testing.T) {
chargeParams := &stripe.ChargeParams{
Amount: 1000,
Currency: currency.USD,
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "4000000000000077",
Month: "06",
Year: "20",
},
},
}
charge, err := charge.New(chargeParams)
if err != nil {
t.Error(err)
}
params := &stripe.AccountParams{
Managed: true,
Country: "US",
LegalEntity: &stripe.LegalEntity{
Type: stripe.Individual,
DOB: stripe.DOB{
Day: 1,
Month: 2,
Year: 1990,
},
},
}
acc, err := account.New(params)
if err != nil {
t.Error(err)
}
transferParams := &stripe.TransferParams{
Amount: 100,
Currency: currency.USD,
Dest: acc.ID,
SourceTx: charge.ID,
}
target, err := New(transferParams)
if err != nil {
t.Error(err)
}
if target.Amount != transferParams.Amount {
t.Errorf("Amount %v does not match expected amount %v\n", target.Amount, transferParams.Amount)
}
if target.Currency != transferParams.Currency {
t.Errorf("Curency %q does not match expected currency %q\n", target.Currency, transferParams.Currency)
}
if target.Created == 0 {
t.Errorf("Created date is not set\n")
}
if target.Date == 0 {
t.Errorf("Date is not set\n")
}
if target.SourceTx != transferParams.SourceTx {
t.Errorf("SourceTx %q does not match expected SourceTx %q\n", target.SourceTx, transferParams.SourceTx)
}
if target.Type != StripeAccount {
t.Errorf("Unexpected type %q\n", target.Type)
}
account.Del(acc.ID)
}
开发者ID:captain401,项目名称:stripe-go,代码行数:75,代码来源:client_test.go
示例15: HandleConfirmation
func (s *Server) HandleConfirmation(w http.ResponseWriter, r *http.Request) {
// POST /reservations/confirmation
if r.Method != "POST" {
http.Error(w, "Method must be POST", http.StatusBadRequest)
return
}
if err := r.ParseForm(); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
var vars ConfirmationVars
if err := s.decoder.Decode(&vars, r.PostForm); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// Look up requested tours.
var tourIDs []int32
for _, item := range vars.Items {
tourIDs = append(tourIDs, item.TourID)
}
tourDetails, err := s.store.GetTourDetailsByID(tourIDs)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Compute total.
var total float64
for _, item := range vars.Items {
tourDetail, ok := tourDetails[item.TourID]
if !ok {
http.Error(w, fmt.Sprintf("Invalid tour ID: %d", item.TourID), http.StatusBadRequest)
return
}
total += float64(item.Quantity) * tourDetail.Price
}
// Convert float64(13.57) to uint64(1357).
stripeAmount := uint64(total*100 + 0.5)
// Add order to database.
orderID, err := s.store.CreateOrder(vars.Name, vars.Email, vars.Hotel, vars.Mobile, vars.Items)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Charge to Stripe.
stripe.Key = s.stripeSecretKey
ch, err := charge.New(&stripe.ChargeParams{
Amount: stripeAmount,
Currency: "USD",
Source: &stripe.SourceParams{Token: vars.StripeToken},
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Update order in database to record payment.
if err := s.store.UpdateOrderPaymentRecorded(orderID); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Email the customer.
if err := s.emailCustomer(&vars); err != nil {
log.Print(err)
}
// Render confirmation page.
data := &ConfirmationData{
Charge: ch,
DisplayAmount: fmt.Sprintf("%d.%02d", ch.Amount/100, ch.Amount%100),
}
tmpl, err := template.ParseFiles(path.Join(s.templatesDir, "confirmation.html"))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tmpl.Execute(w, data); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
开发者ID:btba,项目名称:praha,代码行数:85,代码来源:confirmation.go
示例16: Test
//Invoked by dispatch to make a purchase
func Test(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
r.ParseForm()
var name string
var numberOfGuests string
var date string
var email string
var tok string
var hotel string
used := false
for k, v := range r.Form {
if k == "reservationName" {
name = strings.Join(v, "")
} else if k == "numberOfGuests" {
numberOfGuests = strings.Join(v, "")
} else if k == "token[used]" {
used = true
} else if k == "date" {
date = strings.Join(v, "")
} else if k == "token[email]" {
email = strings.Join(v, "")
} else if k == "token[id]" {
tok = strings.Join(v, "")
} else if k == "hotel" {
hotel = strings.Join(v, "")
} else {
fmt.Println(k + ":" + strings.Join(v, ""))
}
}
if !used {
fmt.Fprintf(w, "false")
return
}
fmt.Println(name + " " + numberOfGuests)
hotel = strings.ToLower(hotel)
stripe.Key = "sk_live_mMpPNXsrCR28xchnYnMXuv0J"
cost, _ := strconv.Atoi(numberOfGuests)
params := &stripe.ChargeParams{
Amount: S.Prices()[hotel] * uint64(cost),
Currency: "usd",
Desc: "Daycation Daypass at " + hotel,
Email: email,
}
params.SetSource(tok)
ch, err := charge.New(params)
if err != nil {
fmt.Println("error while trying to charge a cc", err)
fmt.Fprintf(w, "false")
return
}
fmt.Println("debit created successfully %d\n", ch.ID)
fmt.Println(db.Purchase(hotel, name, date, numberOfGuests, email))
/* body, err := ioutil.ReadAll(r.Body)
if err != nil {
panic(err)
}
var parsed map[string]interface{}
err = json.Unmarshal([]byte(string(body)), &parsed)
if err != nil {
panic(err)
}
data := parsed["data"].(map[string]interface{})
object := data["object"].(map[string]interface{})
metadata := object["metadata"].(map[string]interface{})
amount := object["amount"].(float64)
num := int64(amount) / 10
fmt.Println(metadata)
fmt.Println(amount)
fmt.Println(num)
fmt.Println("called")*/
fmt.Fprintf(w, "true")
}
开发者ID:daycationapp,项目名称:infrastructure,代码行数:89,代码来源:test.go
示例17: TestTransferNew
func TestTransferNew(t *testing.T) {
chargeParams := &stripe.ChargeParams{
Amount: 1000,
Currency: currency.USD,
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "4000000000000077",
Month: "06",
Year: "20",
},
},
}
charge.New(chargeParams)
recipientParams := &stripe.RecipientParams{
Name: "Recipient Name",
Type: recipient.Individual,
Bank: &stripe.BankAccountParams{
Country: "US",
Routing: "110000000",
Account: "000123456789",
},
}
rec, _ := recipient.New(recipientParams)
transferParams := &stripe.TransferParams{
Amount: 100,
Currency: currency.USD,
Recipient: rec.ID,
Desc: "Transfer Desc",
Statement: "Transfer",
}
target, err := New(transferParams)
if err != nil {
t.Error(err)
}
if target.Amount != transferParams.Amount {
t.Errorf("Amount %v does not match expected amount %v\n", target.Amount, transferParams.Amount)
}
if target.Currency != transferParams.Currency {
t.Errorf("Curency %q does not match expected currency %q\n", target.Currency, transferParams.Currency)
}
if target.Created == 0 {
t.Errorf("Created date is not set\n")
}
if target.Date == 0 {
t.Errorf("Date is not set \n")
}
if target.Desc != transferParams.Desc {
t.Errorf("Description %q does not match expected description %q\n", target.Desc, transferParams.Desc)
}
if target.Recipient.ID != transferParams.Recipient {
t.Errorf("Recipient %q does not match expected recipient %q\n", target.Recipient.ID, transferParams.Recipient)
}
if target.Statement != transferParams.Statement {
t.Errorf("Statement %q does not match expected statement %q\n", target.Statement, transferParams.Statement)
}
if target.Bank == nil {
t.Errorf("Bank account is not set\n")
}
if target.Status != Pending {
t.Errorf("Unexpected status %q\n", target.Status)
}
if target.Type != Bank {
t.Errorf("Unexpected type %q\n", target.Type)
}
recipient.Del(rec.ID)
}
开发者ID:captain401,项目名称:stripe-go,代码行数:83,代码来源:client_test.go
示例18: TestRefundNew
func TestRefundNew(t *testing.T) {
chargeParams := &stripe.ChargeParams{
Amount: 1000,
Currency: currency.USD,
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "378282246310005",
Month: "06",
Year: "20",
},
},
}
res, err := charge.New(chargeParams)
if err != nil {
t.Error(err)
}
// full refund
ref, err := New(&stripe.RefundParams{Charge: res.ID})
if err != nil {
t.Error(err)
}
if ref.Charge != res.ID {
t.Errorf("Refund charge %q does not match expected value %v\n", ref.Charge, res.ID)
}
target, err := charge.Get(res.ID, nil)
if err != nil {
t.Error(err)
}
if !target.Refunded || target.Refunds == nil {
t.Errorf("Expected to have refunded this charge\n")
}
if len(target.Refunds.Values) != 1 {
t.Errorf("Expected to have a refund, but instead have %v\n", len(target.Refunds.Values))
}
if target.Refunds.Values[0].Amount != target.AmountRefunded {
t.Errorf("Refunded amount %v does not match amount refunded %v\n", target.Refunds.Values[0].Amount, target.AmountRefunded)
}
if target.Refunds.Values[0].Currency != target.Currency {
t.Errorf("Refunded currency %q does not match charge currency %q\n", target.Refunds.Values[0].Currency, target.Currency)
}
if len(target.Refunds.Values[0].Tx.ID) == 0 {
t.Errorf("Refund transaction not set\n")
}
if target.Refunds.Values[0].Charge != target.ID {
t.Errorf("Refund charge %q does not match expected value %v\n", target.Refunds.Values[0].Charge, target.ID)
}
res, err = charge.New(chargeParams)
// partial refund
refundParams := &stripe.RefundParams{
Charge: res.ID,
Amount: 253,
}
New(refundParams)
target, err = charge.Get(res.ID, nil)
if err != nil {
t.Error(err)
}
if target.Refunded {
t.Errorf("Partial refund should not be marked as Refunded\n")
}
if target.AmountRefunded != refundParams.Amount {
t.Errorf("Refunded amount %v does not match expected amount %v\n", target.AmountRefunded, refundParams.Amount)
}
// refund with reason
res, err = charge.New(chargeParams)
if err != nil {
t.Error(err)
}
New(&stripe.RefundParams{Charge: res.ID, Reason: RefundFraudulent})
target, err = charge.Get(res.ID, nil)
if err != nil {
t.Error(err)
}
if target.FraudDetails.UserReport != "fraudulent" {
t.Errorf("Expected a fraudulent UserReport for charge refunded with reason=fraudulent but got: %s",
//.........这里部分代码省略.........
开发者ID:carriercomm,项目名称:stripe-go,代码行数:101,代码来源:client_test.go
示例19: TestBalanceGetTx
func TestBalanceGetTx(t *testing.T) {
chargeParams := &stripe.ChargeParams{
Amount: 1002,
Currency: currency.USD,
Desc: "charge transaction",
}
chargeParams.SetSource(&stripe.CardParams{
Number: "378282246310005",
Month: "06",
Year: "20",
})
res, _ := charge.New(chargeParams)
target, err := GetTx(res.Tx.ID, nil)
if err != nil {
t.Error(err)
}
if uint64(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.Desc != chargeParams.Desc {
t.Errorf("Description %q does not match expected description %q\n", target.Desc, chargeParams.Desc)
}
if target.Available == 0 {
t.Errorf("Available date is not set\n")
}
if target.Created == 0 {
t.Errorf("Created date is not set\n")
}
if target.Fee == 0 {
t.Errorf("Fee is not set\n")
}
if target.FeeDetails == nil || len(target.FeeDetails) != 1 {
t.Errorf("Fee details are not set")
}
if target.FeeDetails[0].Amount == 0 {
t.Errorf("Fee detail amount is not set\n")
}
if len(target.FeeDetails[0].Currency) == 0 {
t.Errorf("Fee detail currency is not set\n")
}
if len(target.FeeDetails[0].Desc) == 0 {
t.Errorf("Fee detail description is not set\n")
}
if target.Net == 0 {
t.Errorf("Net is not set\n")
}
if target.Status != TxPending {
t.Errorf("Status %v does not match expected value\n", target.Status)
}
if target.Type != TxCharge {
t.Errorf("Type %v does not match expected value\n", target.Type)
}
if target.Src != res.ID {
t.Errorf("Source %q does not match expeted value %q\n", target.Src, res.ID)
}
}
开发者ID:mousadialo,项目名称:stripe-go,代码行数:76,代码来源:client_test.go
注:本文中的github.com/stripe/stripe-go/charge.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论