paypal/payment_test.go

60 lines
1.2 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) {
2015-12-22 05:31:12 +01:00
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
2015-11-02 10:39:07 +01:00
amount := Amount{
2015-12-22 05:31:12 +01:00
Total: "15.11",
2015-11-02 10:39:07 +01:00
Currency: "USD",
}
2015-12-22 05:31:12 +01:00
p, err := c.CreateDirectPaypalPayment(amount, "http://example.com", "http://example.com", "test payment")
2015-11-16 06:11:27 +01:00
2015-12-22 05:31:12 +01:00
if err != nil || p.ID == "" {
t.Errorf("Test paypal payment is not created")
2015-11-16 06:11:27 +01:00
}
}
2015-11-25 11:30:25 +01:00
func TestGetPayment(t *testing.T) {
2015-12-22 05:31:12 +01:00
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
2015-11-25 11:30:25 +01:00
2015-12-22 05:31:12 +01:00
_, err := c.GetPayment(testPaymentID)
2015-11-25 11:30:25 +01:00
if err == nil {
2015-12-22 05:31:12 +01:00
t.Errorf("404 for this payment 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) {
2015-12-22 05:31:12 +01:00
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
2015-11-25 11:30:25 +01:00
payments, _ := c.GetPayments()
2015-12-22 05:31:12 +01:00
if len(payments) != 5 {
t.Errorf("5 payments must be returned for GetPayments")
2015-11-25 11:30:25 +01:00
}
}
2015-11-16 06:11:27 +01:00
func TestExecuteApprovedPayment(t *testing.T) {
2015-12-22 05:31:12 +01:00
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken()
2015-11-16 06:11:27 +01:00
2015-12-22 05:31:12 +01:00
_, err := c.ExecuteApprovedPayment(testPaymentID, testPayerID)
2015-11-02 10:39:07 +01:00
if err == nil {
2015-12-22 05:31:12 +01:00
t.Errorf("404 for this payment ID")
2015-12-17 08:50:25 +01:00
} else {
fmt.Println(err.Error())
2015-11-02 10:39:07 +01:00
}
}