mirror of
https://github.com/plutov/paypal.git
synced 2025-02-02 15:10:36 +01:00
Added Details Struct and added Details Member to Amount struct so payments that includ shipping cost can be send with the Transaction struct
This commit is contained in:
parent
d30e9ced1e
commit
f9d30e2c20
|
@ -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()
|
||||
|
|
16
types.go
16
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:"-"`
|
||||
|
|
Loading…
Reference in New Issue
Block a user