This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathe2e_test.go
135 lines (120 loc) · 4.2 KB
/
e2e_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package paypal
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestPayment(t *testing.T) {
withContext(func(client *Client) {
Convey("With the payments endpoint", t, func() {
Convey("Creating a payment with valid data should be successful", func() {
billingAddress := Address{
Line1: "111 First Street",
City: "Saratoga",
State: "CA",
PostalCode: "95070",
CountryCode: "US",
}
creditCard := CreditCard{
Number: "4417119669820331",
Type: "visa",
ExpireMonth: "11",
ExpireYear: "2018",
CVV2: "874",
FirstName: "Betsy",
LastName: "Buyer",
BillingAddress: &billingAddress,
}
payer := Payer{
PaymentMethod: PaymentMethodCreditCard,
FundingInstruments: []FundingInstrument{
FundingInstrument{
CreditCard: &creditCard,
},
},
}
amountDetail := Details{
Subtotal: "7.41",
Tax: "0.03",
Shipping: "0.03",
}
amount := Amount{
Total: "7.47",
Currency: "USD",
Details: &amountDetail,
}
transaction := Transaction{
Amount: &amount,
Description: "This is the payment transaction description.",
}
payment := Payment{
Intent: PaymentIntentSale,
Payer: &payer,
Transactions: []Transaction{transaction},
}
newPaymentResp, err := client.CreatePayment(payment)
So(err, ShouldBeNil)
So(newPaymentResp.Intent, ShouldEqual, PaymentIntentSale)
So(newPaymentResp.ID, ShouldNotBeNil)
// This requires manual test as the payer needs to approve inside Paypal
// Convey("Execute the newly created payment should be successful", func() {
// resp, err := client.ExecutePayment(newPaymentResp.ID, payer.ID, nil)
//
// So(err, ShouldBeNil)
// So(resp.ID, ShouldEqual, newPaymentResp.ID)
// So(resp.State, ShouldEqual, PaymentStateApproved)
// })
Convey("Fetching the newly created payment should return valid results", func() {
payment, err := client.GetPayment(newPaymentResp.ID)
So(err, ShouldBeNil)
So(payment.ID, ShouldEqual, newPaymentResp.ID)
So(payment.Intent, ShouldEqual, PaymentIntentSale)
So(payment.Payer.PaymentMethod, ShouldEqual, PaymentMethodCreditCard)
So(payment.Transactions[0].RelatedResources[0], ShouldNotBeNil)
Convey("With the sale endpoints", func() {
Convey("Fetching an existing sale should return valid data", func() {
sale, err := client.GetSale(newPaymentResp.Transactions[0].RelatedResources[0].Sale.ID)
So(err, ShouldBeNil)
So(sale.ID, ShouldEqual, newPaymentResp.Transactions[0].RelatedResources[0].Sale.ID)
// Cannot test refund as it require that a payment is approved and completed
// Convey("A partial refund for an existing sale should be successful", func() {
// amount := Amount{
// Total: "2.34",
// Currency: "USD",
// }
//
// refund, err := client.RefundSale(sale.ID, &amount)
// So(err, ShouldBeNil)
//
// refundedSale, err := client.GetSale(newPaymentResp.Transactions[0].RelatedResources[0].Sale.ID)
//
// So(err, ShouldBeNil)
// So(refund.Amount.Total, ShouldEqual, amount.Total)
// So(refund.ParentPayment, ShouldEqual, payment.ID)
// So(refundedSale.State, ShouldEqual, SaleStatePartiallyRefunded)
// So(refundedSale.Amount.Total, ShouldEqual, "5.13")
//
// Convey("Retrieving the new refund should return valid results", func() {
// newRefund, err := client.GetRefund(refund.ID)
//
// So(err, ShouldBeNil)
// So(newRefund.ID, ShouldEqual, refund.ID)
// So(newRefund.Amount, ShouldResemble, refund.Amount)
//
// })
// })
})
})
})
Convey("List payments should include the newly created payment", func() {
payments, err := client.ListPayments(map[string]string{
"count": "10",
"sort_by": "create_time",
})
So(err, ShouldBeNil)
So(len(payments), ShouldBeGreaterThan, 0)
So(payments[0].ID, ShouldEqual, newPaymentResp.ID)
})
})
})
})
}