Merge pull request #34 from florin-rada/amount_details

Added Details Struct and added Details Member to Amount struct
This commit is contained in:
Alex Pliutau 2017-09-27 17:06:14 -05:00 committed by GitHub
commit f48535a92e
2 changed files with 67 additions and 2 deletions

View File

@ -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()

View File

@ -74,6 +74,7 @@ type (
Amount struct {
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:"-"`