paypale/payment_test.go

61 lines
1.3 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"
2016-01-18 09:42:42 +01:00
"strconv"
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()
2016-07-21 05:51:44 +02:00
if len(payments) != 0 {
t.Errorf("0 payments must be returned for GetPayments. Returned: " + strconv.Itoa(len(payments)))
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
}
}