Esempio n. 1
0
func TestTransfer(t *testing.T) {
	const (
		RecipientID = "recp_test_50894vc13y8z4v51iuc"
		TransferID  = "trsf_test_4yqacz8t3cbipcj766u"
	)

	client := testutil.NewFixedClient(t)

	transfer := &omise.Transfer{}
	client.MustDo(transfer, &CreateTransfer{Amount: 192188})
	a.Equal(t, TransferID, transfer.ID)
	a.Equal(t, int64(192188), transfer.Amount)

	transfer = &omise.Transfer{}
	client.MustDo(transfer, &RetrieveTransfer{TransferID})
	a.Equal(t, TransferID, transfer.ID)
	a.Equal(t, RecipientID, transfer.Recipient)
	if a.NotNil(t, transfer.BankAccount) {
		a.Equal(t, "6789", transfer.BankAccount.LastDigits)
	}

	transfer = &omise.Transfer{}
	client.MustDo(transfer, &UpdateTransfer{
		TransferID: TransferID,
		Amount:     192189,
	})
	a.Equal(t, TransferID, transfer.ID)
	a.Equal(t, int64(192189), transfer.Amount)

	del := &omise.Deletion{}
	client.MustDo(del, &DestroyTransfer{TransferID})
	a.Equal(t, TransferID, del.ID)
	a.True(t, del.Deleted)
}
Esempio n. 2
0
func TestRecipient(t *testing.T) {
	const (
		RecipientID   = "recp_test_50894vc13y8z4v51iuc"
		BankAccountID = ""
	)

	client := testutil.NewFixedClient(t)

	recipient := &omise.Recipient{}
	client.MustDo(recipient, &RetrieveRecipient{RecipientID})
	a.Equal(t, RecipientID, recipient.ID)
	if a.NotNil(t, recipient.BankAccount) {
		a.Equal(t, "6789", recipient.BankAccount.LastDigits)
	}

	recipients := &omise.RecipientList{}
	client.MustDo(recipients, &ListRecipients{})
	if a.Len(t, recipients.Data, 1) {
		a.Equal(t, RecipientID, recipients.Data[0].ID)
	}

	client.MustDo(recipient, &UpdateRecipient{
		RecipientID: RecipientID,
		Email:       "*****@*****.**",
	})
	a.Equal(t, "*****@*****.**", recipient.Email)

	del := &omise.Deletion{}
	client.MustDo(del, &DestroyRecipient{RecipientID})
	a.Equal(t, recipient.ID, del.ID)
}
Esempio n. 3
0
func TestRefund(t *testing.T) {
	const (
		ChargeID      = "chrg_test_4yq7duw15p9hdrjp8oq"
		TransactionID = "trxn_test_4yqmv79fzpy0gmz5mmq"
		RefundID      = "rfnd_test_4yqmv79ahghsiz23y3c"
	)

	client := testutil.NewFixedClient(t)

	refund := &omise.Refund{}
	client.MustDo(refund, &RetrieveRefund{ChargeID, RefundID})
	a.Equal(t, RefundID, refund.ID)
	a.Equal(t, ChargeID, refund.Charge)
	a.Equal(t, TransactionID, refund.Transaction)

	refund = &omise.Refund{}
	client.MustDo(refund, &CreateRefund{ChargeID, 10000, false})
	a.Equal(t, RefundID, refund.ID)
	a.Equal(t, int64(10000), refund.Amount)

	e := client.Do(nil, &RetrieveRefund{ChargeID, "not_exist"})
	if a.Error(t, e) {
		a.EqualError(t, e, "(404/not_found) refund 404 was not found")
	}
}
Esempio n. 4
0
func TestBalance(t *testing.T) {
	client := testutil.NewFixedClient(t)
	balance := &omise.Balance{}
	client.MustDo(balance, &RetrieveBalance{})
	a.Equal(t, int64(96094), balance.Total)
	a.Equal(t, "thb", balance.Currency)
}
Esempio n. 5
0
func TestSearch(t *testing.T) {
	const Query = "amount:1000"
	client := testutil.NewFixedClient(t)

	result := &omise.ChargeSearchResult{}
	client.MustDo(result, &Search{
		Scope: omise.ChargeScope,
		Query: Query,
	})

	a.Equal(t, Query, result.Query)
	a.Equal(t, 1, result.Page)
	a.Equal(t, 3, result.TotalPages)

	charge := result.Data[0]
	a.Equal(t, "chrg_test_54i01932u4ts67cop81", charge.ID)
}
Esempio n. 6
0
func TestClient_TransportError(t *testing.T) {
	client := testutil.NewFixedClient(t)

	e := client.Do(&struct{}{}, &internal.Op{
		Endpoint: internal.API,
		Method:   "GET",
		Path:     "/malformed",
	})
	if a.NotNil(t, e) {
		err, ok := e.(*ErrTransport)
		if a.True(t, ok, "error returned in not *omise.ErrTransport: ") {
			_, ok := err.Err.(*json.SyntaxError)
			a.True(t, ok, "error does not wrap *json.SyntaxError")
			a.Contains(t, string(err.Buffer), "not a valid JSON")
		}
	}
}
Esempio n. 7
0
func TestToken(t *testing.T) {
	const TokenID = "tokn_test_4yq8lbecl0q6dsjzxr5"
	client := testutil.NewFixedClient(t)

	token := &omise.Token{}
	client.MustDo(token, &CreateToken{
		Name:            "JOHN DOE",
		Number:          "4242424242424242",
		ExpirationMonth: 1,
		ExpirationYear:  2017,
		SecurityCode:    "123",
	})
	a.Equal(t, TokenID, token.ID)

	token = &omise.Token{}
	client.MustDo(token, &RetrieveToken{TokenID})
	a.Equal(t, TokenID, token.ID)
}
Esempio n. 8
0
func TestTransaction(t *testing.T) {
	const (
		TransactionID  = "trxn_test_4yq7duwb9jts1vxgqua"
		TransactionID2 = "trxn_test_4yqafnvlztbf3908vs1"
	)

	client := testutil.NewFixedClient(t)

	tx := &omise.Transaction{}
	client.MustDo(tx, &RetrieveTransaction{TransactionID})
	a.Equal(t, TransactionID, tx.ID)

	transactions := &omise.TransactionList{}
	client.MustDo(transactions, &ListTransactions{})
	if a.Len(t, transactions.Data, 2) {
		a.Equal(t, TransactionID, transactions.Data[0].ID)
		a.Equal(t, TransactionID2, transactions.Data[1].ID)
	}
}
Esempio n. 9
0
func TestDispute(t *testing.T) {
	const (
		DisputeID = "dspt_test_5089off452g5m5te7xs"
	)

	client := testutil.NewFixedClient(t)

	// 4 possible states.
	disputes := &omise.DisputeList{}
	client.MustDo(disputes, &ListDisputes{})
	if a.Len(t, disputes.Data, 1) {
		a.Equal(t, DisputeID, disputes.Data[0].ID)
	}

	disputes = &omise.DisputeList{}
	client.MustDo(disputes, &ListDisputes{State: omise.Open})
	if a.Len(t, disputes.Data, 1) {
		a.Equal(t, DisputeID, disputes.Data[0].ID)
		a.Equal(t, omise.Open, disputes.Data[0].Status)
	}

	disputes = &omise.DisputeList{}
	client.MustDo(disputes, &ListDisputes{State: omise.Pending})
	if a.Len(t, disputes.Data, 1) {
		a.Equal(t, DisputeID, disputes.Data[0].ID)
		a.Equal(t, omise.Pending, disputes.Data[0].Status)
	}

	disputes = &omise.DisputeList{}
	client.MustDo(disputes, &ListDisputes{State: omise.Closed})
	if a.Len(t, disputes.Data, 1) {
		a.Equal(t, DisputeID, disputes.Data[0].ID)
		a.Equal(t, omise.Won, disputes.Data[0].Status)
	}

	// single instances
	dispute := &omise.Dispute{}
	client.MustDo(dispute, &RetrieveDispute{DisputeID})
	a.Equal(t, DisputeID, dispute.ID)

	client.MustDo(dispute, &UpdateDispute{DisputeID, "Your dispute message"})
	a.Equal(t, "Your dispute message", dispute.Message)
}
Esempio n. 10
0
func TestCharge(t *testing.T) {
	const (
		ChargeID      = "chrg_test_4yq7duw15p9hdrjp8oq"
		TransactionID = "trxn_test_4yq7duwb9jts1vxgqua"
		CardID        = "card_test_4yq6tuucl9h4erukfl0"
		RefundID      = "rfnd_test_4yqmv79ahghsiz23y3c"
	)

	client := testutil.NewFixedClient(t)

	charge := &omise.Charge{}
	client.MustDo(charge, &CreateCharge{})
	a.Equal(t, ChargeID, charge.ID)

	charge = &omise.Charge{}
	client.MustDo(charge, &RetrieveCharge{ChargeID})
	a.Equal(t, ChargeID, charge.ID)
	a.Equal(t, TransactionID, charge.Transaction)
	a.Equal(t, CardID, charge.Card.ID)
	if a.Len(t, charge.Refunds.Data, 1) {
		a.Equal(t, RefundID, charge.Refunds.Data[0].ID)
	}

	charges := &omise.ChargeList{}
	client.MustDo(charges, &ListCharges{})
	if a.Len(t, charges.Data, 1) {
		a.Equal(t, "chrg_test_4yq7duw15p9hdrjp8oq", charges.Data[0].ID)
	}

	client.MustDo(charge, &UpdateCharge{
		ChargeID:    ChargeID,
		Description: "Charge for order 3947 (XXL)",
	})
	if a.NotNil(t, charge.Description) {
		a.Equal(t, "Charge for order 3947 (XXL)", *charge.Description)
	}

	e := client.Do(nil, &RetrieveCharge{"not_exist"})
	if a.Error(t, e) {
		a.EqualError(t, e, "(404/not_found) customer missing was not found")
	}
}
Esempio n. 11
0
func TestCustomer(t *testing.T) {
	const (
		CustomerID = "cust_test_4yq6txdpfadhbaqnwp3"
		CardID     = "card_test_4yq6tuucl9h4erukfl0"
	)

	client := testutil.NewFixedClient(t)

	customer := &omise.Customer{}
	client.MustDo(customer, &CreateCustomer{})
	a.Equal(t, CustomerID, customer.ID)

	customer = &omise.Customer{}
	client.MustDo(customer, &RetrieveCustomer{CustomerID})
	a.Equal(t, CustomerID, customer.ID)
	a.Equal(t, CardID, customer.DefaultCard)
	if a.Len(t, customer.Cards.Data, 1) {
		a.Equal(t, CardID, customer.Cards.Data[0].ID)
	}

	customers := &omise.CustomerList{}
	client.MustDo(customers, &ListCustomers{})
	if a.Len(t, customers.Data, 1) {
		a.Equal(t, CustomerID, customers.Data[0].ID)
	}

	client.MustDo(customer, &UpdateCustomer{
		CustomerID: customer.ID,
		Email:      "*****@*****.**",
	})
	a.Equal(t, "*****@*****.**", customer.Email)

	del := &omise.Deletion{}
	client.MustDo(del, &DestroyCustomer{CustomerID})
	a.Equal(t, CustomerID, del.ID)

	e := client.Do(nil, &RetrieveCustomer{"not_exist"})
	if a.Error(t, e) {
		a.EqualError(t, e, "(404/not_found) customer missing was not found")
	}
}
Esempio n. 12
0
func TestCard(t *testing.T) {
	client := testutil.NewFixedClient(t)
	card := &omise.Card{}
	client.MustDo(card, &RetrieveCard{CustomerID, CardID})
	a.Equal(t, CardID, card.ID)

	card = &omise.Card{}
	e := client.Do(card, &RetrieveCard{CustomerID, "not_exist"})
	if a.Error(t, e) {
		a.EqualError(t, e, "(404/not_found) customer missing was not found")
	}

	client.MustDo(card, &UpdateCard{
		CustomerID: CustomerID,
		CardID:     CardID,
		Name:       "JOHN W. DOE",
	})
	a.Equal(t, "JOHN W. DOE", card.Name)

	del := &omise.Deletion{}
	client.MustDo(del, &DestroyCard{CustomerID, CardID})
	a.Equal(t, card.ID, del.ID)
}
Esempio n. 13
0
func TestEvent(t *testing.T) {
	const (
		EventID    = "evnt_test_526yctupnje5mbldskd"
		TransferID = "trsf_test_526yctqob5djkckq88a"
		EventID2   = "evnt_test_5232t5tlhjwh7nbi14g"
	)

	client := testutil.NewFixedClient(t)

	event := &omise.Event{}
	client.MustDo(event, &RetrieveEvent{EventID})
	a.Equal(t, EventID, event.ID)
	a.Equal(t, "transfer.destroy", event.Key)
	a.Equal(t, TransferID, event.Data.(*omise.Deletion).ID)

	events := &omise.EventList{}
	client.MustDo(events, &ListEvents{})
	a.Len(t, events.Data, 20)

	event = events.Data[0]
	a.Equal(t, EventID2, event.ID)
	a.Equal(t, "customer.create", event.Key)
}
Esempio n. 14
0
func TestAccount(t *testing.T) {
	client := testutil.NewFixedClient(t)
	account := &omise.Account{}
	client.MustDo(account, &RetrieveAccount{})
	a.Equal(t, account.ID, "acct_4yq6tcsyoged5c0ocxd")
}