Ejemplo n.º 1
0
func TestChargeSourceForSourceObject(t *testing.T) {
	sourceParams := &stripe.SourceObjectParams{
		Type:     "bitcoin",
		Amount:   1000,
		Currency: currency.USD,
		Owner: &stripe.SourceOwnerParams{
			Email: "*****@*****.**",
		},
	}

	s, err := source.New(sourceParams)
	if err != nil {
		t.Fatalf("%+v", err)
	}

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

	chargeParams.SetSource(s.ID)

	ch, _ := New(chargeParams)

	if len(ch.ID) == 0 {
		t.Error("ID is nil for Charge")
	}

	if ch.Source == nil {
		t.Error("Source is nil for Charge, should be Source property")
	}

	if ch.Source.Type != stripe.PaymentSourceObject {
		t.Error("Source Type for Charge created by Source should be `source`")
	}

	source := ch.Source.SourceObject

	if len(source.ID) == 0 {
		t.Error("Source ID is nil for Charge `source` SourceObject property")
	}

	if source.Amount == 0 {
		t.Error("Amount is empty for Charge `source` SourceObject property")
	}

	if source.Display() != "Consumed bitcoin source (1000 usd)" {
		t.Error("Display value did not match expectation")
	}
}
Ejemplo n.º 2
0
func TestSourceObjectNewGet(t *testing.T) {
	sourceParams := &stripe.SourceObjectParams{
		Type:     "bitcoin",
		Amount:   1000,
		Currency: currency.USD,
		Owner: &stripe.SourceOwnerParams{
			Email: "*****@*****.**",
		},
	}

	s, err := source.New(sourceParams)
	if err != nil {
		t.Fatalf("%+v", 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: s.ID,
		},
	})

	if src.SourceObject.Owner.Email != "*****@*****.**" {
		t.Errorf("Source object owner email %q was not as expected.",
			src.SourceObject.Owner.Email)
	}

	src, err = Get(src.ID, &stripe.CustomerSourceParams{
		Customer: customer.ID,
	})
	if err != nil {
		t.Error(err)
	}

	if src.SourceObject.Owner.Email != "*****@*****.**" {
		t.Errorf("Source object owner email %q was not as expected.",
			src.SourceObject.Owner.Email)
	}
}