paypale/payment_test.go

70 lines
1.4 KiB
Go
Raw Normal View History

2015-11-02 10:39:07 +01:00
package paypalsdk
import (
2015-12-17 08:50:25 +01:00
"fmt"
2015-11-02 10:39:07 +01:00
"testing"
)
func TestCreateDirectPaypalPayment(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c.Token = &TokenResponse{
Token: "invalidtoken",
}
amount := Amount{
2015-11-25 11:30:25 +01:00
Total: "15.1111",
2015-11-02 10:39:07 +01:00
Currency: "USD",
}
2015-11-25 11:30:25 +01:00
_, err := c.CreateDirectPaypalPayment(amount, "http://example.com", "http://example.com", "test payment")
2015-11-16 06:11:27 +01:00
if err == nil {
t.Errorf("Error must be returned for invalid token")
2015-12-17 08:50:25 +01:00
} else {
fmt.Println(err.Error())
2015-11-16 06:11:27 +01:00
}
}
2015-11-25 11:30:25 +01:00
func TestGetPayment(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c.Token = &TokenResponse{
Token: "invalidtoken",
}
_, err := c.GetPayment("PAY-TEST-123")
if err == nil {
t.Errorf("Error must be returned for invalid ID")
2015-12-17 08:50:25 +01:00
} else {
fmt.Println(err.Error())
2015-11-25 11:30:25 +01:00
}
}
func TestGetPayments(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c.Token = &TokenResponse{
Token: "invalidtoken",
}
payments, _ := c.GetPayments()
if len(payments) != 0 {
t.Errorf("0 payments must be returned for unautgorized request")
}
}
2015-11-16 06:11:27 +01:00
func TestExecuteApprovedPayment(t *testing.T) {
c, _ := NewClient("clid", "secret", APIBaseSandBox)
c.Token = &TokenResponse{
Token: "invalidtoken",
}
_, err := c.ExecuteApprovedPayment("PAY-6RV70583SB702805EKEYSZ6Y", "7E7MGXCWTTKK2")
2015-11-02 10:39:07 +01:00
if err == nil {
t.Errorf("Error must be returned for invalid token")
2015-12-17 08:50:25 +01:00
} else {
fmt.Println(err.Error())
2015-11-02 10:39:07 +01:00
}
}