From f9d30e2c208801df20d670bbaa3b98bc5e6620d5 Mon Sep 17 00:00:00 2001
From: Rada Florin <florin.rada87@yahoo.com>
Date: Tue, 26 Sep 2017 18:26:02 +0300
Subject: [PATCH] Added Details Struct and added Details Member to Amount
 struct so payments that includ shipping cost can be send with the Transaction
 struct

---
 integration_test.go | 59 ++++++++++++++++++++++++++++++++++++++++++++-
 types.go            | 16 ++++++++++--
 2 files changed, 72 insertions(+), 3 deletions(-)

diff --git a/integration_test.go b/integration_test.go
index 1d410de..a1f623e 100644
--- a/integration_test.go
+++ b/integration_test.go
@@ -3,6 +3,8 @@
 package paypalsdk
 
 import (
+	"encoding/json"
+	"fmt"
 	"os"
 	"testing"
 )
@@ -154,7 +156,7 @@ func TestVoidOrder(t *testing.T) {
 
 func TestCreateDirectPaypalPayment(t *testing.T) {
 	c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
-	c.SetLog(os.Stdout)
+	//c.SetLog(os.Stdout)
 	c.GetAccessToken()
 
 	amount := Amount{
@@ -169,6 +171,61 @@ 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://localhost:9000/gb/checkout/payment",
+			CancelURL: "http://localhost:9000/gb/checkout/summary",
+		},
+	}
+	pr, err := c.CreatePayment(p)
+	if err != nil {
+		t.Errorf("Error creating payment.")
+	}
+	pmEnc, _ := json.Marshal(pr)
+	fmt.Printf("pmEnc: %s", pmEnc)
+}
+
 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:"-"`