Ejemplo n.º 1
0
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)
	}
}
Ejemplo n.º 2
0
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
}
Ejemplo n.º 3
0
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)
}
Ejemplo n.º 4
0
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)
}
Ejemplo n.º 5
0
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)
}
Ejemplo n.º 6
0
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)
	}
}
Ejemplo n.º 7
0
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)
}
Ejemplo n.º 8
0
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)
}
Ejemplo n.º 9
0
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",
			target.FraudDetails.UserReport)
	}
}
Ejemplo n.º 10
0
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)
	}
}