diff --git a/integration_test.go b/integration_test.go index 1d410de..ff28907 100644 --- a/integration_test.go +++ b/integration_test.go @@ -169,6 +169,59 @@ func TestCreateDirectPaypalPayment(t *testing.T) { } } +func TestCreatePayment(t *testing.T) { + c, _ := NewClient(testClientID, testSecret, APIBaseSandBox) + c.SetLog(os.Stdout) + c.GetAccessToken() + + p := Payment{ + Intent: "sale", + Payer: &Payer{ + PaymentMethod: "credit_card", + FundingInstruments: []FundingInstrument{{ + CreditCard: &CreditCard{ + Number: "4111111111111111", + Type: "visa", + ExpireMonth: "11", + ExpireYear: "2020", + CVV2: "777", + FirstName: "John", + LastName: "Doe", + }, + }}, + }, + Transactions: []Transaction{{ + Amount: &Amount{ + Currency: "USD", + Total: "10.00", // total cost including shipping + Details: Details{ + Shipping: "3.00", // total shipping cost + Subtotal: "7.00", // total cost without shipping + }, + }, + Description: "My Payment", + ItemList: &ItemList{ + Items: []Item{ + Item{ + Quantity: 2, + Price: "3.50", + Currency: "USD", + Name: "Product 1", + }, + }, + }, + }}, + RedirectURLs: &RedirectURLs{ + ReturnURL: "http://..", + CancelURL: "http://..", + }, + } + pr, err := c.CreatePayment(p) + if err != nil { + t.Errorf("Error creating payment.") + } +} + func TestGetPayment(t *testing.T) { c, _ := NewClient(testClientID, testSecret, APIBaseSandBox) c.GetAccessToken() diff --git a/types.go b/types.go index cbaa1c4..a68290d 100644 --- a/types.go +++ b/types.go @@ -72,8 +72,9 @@ type ( // Amount struct Amount struct { - Currency string `json:"currency"` - Total string `json:"total"` + Currency string `json:"currency"` + Total string `json:"total"` + Details Details `json:"details,omitempty"` } // AmountPayout struct @@ -210,6 +211,17 @@ type ( Value string `json:"value,omitempty"` } + // Details structure used in Amount structures as optional value + Details struct { + Subtotal string `json:"subtotal,omitempty"` + Shipping string `json:"shipping,omitempty"` + Tax string `json:"tax,omitempty"` + HandlingFee string `json:"handling_fee,omitempty"` + ShippingDiscount string `json:"shipping_discount,omitempty"` + Insurance string `json:"insurance,omitempty"` + GiftWrap string `json:"gift_wrap,omitempty"` + } + // ErrorResponse https://developer.paypal.com/docs/api/errors/ ErrorResponse struct { Response *http.Response `json:"-"`