From ab760e856120563ea61f96117979f066408fef87 Mon Sep 17 00:00:00 2001 From: Aliaksandr Pliutau Date: Mon, 2 Nov 2015 10:34:16 +0700 Subject: [PATCH] types --- payment.go | 25 +++++++++++++++++++++---- types.go | 22 +++++++++++++--------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/payment.go b/payment.go index 00af5e3..a6ccf95 100644 --- a/payment.go +++ b/payment.go @@ -1,8 +1,25 @@ package paypalsdk -import () +import ( + "bytes" + "fmt" + "net/http" +) -// CreateDirectCreditCardPayment sends request with payment -func CreateDirectCreditCardPayment(cc CreditCard, amount Amount) error { - return nil +// CreateDirectPaypalPayment sends request with payment +func (c *Client) CreateDirectPaypalPayment(payment PaypalPaymentRequest) (*PaymentResponse, error) { + buf := bytes.NewBuffer([]byte("")) + req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/payment"), buf) + if err != nil { + return &PaymentResponse{}, err + } + + req.SetBasicAuth(c.ClientID, c.Secret) + req.Header.Set("Authorization", "Bearer "+c.Token.Token) + req.Header.Set("Content-type", "application/x-www-form-urlencoded") + + p := PaymentResponse{} + err = c.Send(req, &p) + + return &p, nil } diff --git a/types.go b/types.go index 0b97f96..0bcd75b 100644 --- a/types.go +++ b/types.go @@ -47,20 +47,24 @@ type ( Issue string `json:"issue"` } - // CreditCard - All info about customer's CC - CreditCard struct { - Type string - Number string - ExpireYear int - ExpireMonth int - FirstName string - LastName string + // PaypalPaymentRequest - All info about paypal type payment + PaypalPaymentRequest struct { + Transactions []Transaction + } + + // PaymentResponse structure + PaymentResponse struct { + } + + // Transaction element + Transaction struct { + Amount Amount } // Amount to pay Amount struct { Currency string - Amount float32 + Total float32 } )