mirror of
https://github.com/plutov/paypal.git
synced 2025-01-23 02:11:02 +01:00
Merge pull request #70 from cristaloleg/master
Get rid of escape characters
This commit is contained in:
commit
e31da31dcc
|
@ -27,7 +27,7 @@ func (c *Client) GetAuthorization(authID string) (*Authorization, error) {
|
|||
func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture bool) (*Capture, error) {
|
||||
isFinalStr := strconv.FormatBool(isFinalCapture)
|
||||
|
||||
buf := bytes.NewBuffer([]byte("{\"amount\":{\"currency\":\"" + a.Currency + "\",\"total\":\"" + a.Total + "\"},\"is_final_capture\":" + isFinalStr + "}"))
|
||||
buf := bytes.NewBuffer([]byte(`{"amount":{"currency":"` + a.Currency + `,"total":"` + a.Total + `"},"is_final_capture":` + isFinalStr + `}`))
|
||||
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/authorization/"+authID+"/capture"), buf)
|
||||
if err != nil {
|
||||
return &Capture{}, err
|
||||
|
@ -56,7 +56,7 @@ func (c *Client) VoidAuthorization(authID string) (*Authorization, error) {
|
|||
// PayPal recommends to reauthorize payment after ~3 days
|
||||
// Endpoint: POST /v1/payments/authorization/ID/reauthorize
|
||||
func (c *Client) ReauthorizeAuthorization(authID string, a *Amount) (*Authorization, error) {
|
||||
buf := bytes.NewBuffer([]byte("{\"amount\":{\"currency\":\"" + a.Currency + "\",\"total\":\"" + a.Total + "\"}}"))
|
||||
buf := bytes.NewBuffer([]byte(`{"amount":{"currency":"` + a.Currency + `","total":"` + a.Total + `"}}`))
|
||||
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/authorization/"+authID+"/reauthorize"), buf)
|
||||
if err != nil {
|
||||
return &Authorization{}, err
|
||||
|
|
|
@ -46,7 +46,7 @@ func (c *Client) CreateBillingPlan(plan BillingPlan) (*CreateBillingResp, error)
|
|||
// By default, a new plan is not activated
|
||||
// Endpoint: PATCH /v1/payments/billing-plans/
|
||||
func (c *Client) ActivatePlan(planID string) error {
|
||||
buf := bytes.NewBuffer([]byte("[{\"op\":\"replace\",\"path\":\"/\",\"value\":{\"state\":\"ACTIVE\"}}]"))
|
||||
buf := bytes.NewBuffer([]byte(`[{"op":"replace","path":"/","value":{"state":"ACTIVE"}}]`))
|
||||
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-plans/"+planID), buf)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
10
payment.go
10
payment.go
|
@ -22,10 +22,10 @@ type CreatePaymentResp struct {
|
|||
// CreatePayment is more common function for any kind of payment
|
||||
// Endpoint: POST /v1/payments/payment
|
||||
func (c *Client) CreateDirectPaypalPayment(amount Amount, redirectURI string, cancelURI string, description string) (*PaymentResponse, error) {
|
||||
buf := bytes.NewBuffer([]byte("{\"intent\":\"sale\",\"payer\":{\"payment_method\":\"paypal\"}," +
|
||||
"\"transactions\":[{\"amount\":{\"total\":\"" + amount.Total +
|
||||
"\",\"currency\":\"" + amount.Currency + "\"},\"description\":\"" + description + "\"}],\"redirect_urls\":{\"return_url\":\"" +
|
||||
redirectURI + "\",\"cancel_url\":\"" + cancelURI + "\"}}"))
|
||||
buf := bytes.NewBuffer([]byte(`{"intent":"sale","payer":{"payment_method":"paypal"},` +
|
||||
`"transactions":[{"amount":{"total":"` + amount.Total +
|
||||
`","currency":"` + amount.Currency + `"},"description":"` + description + `"}],"redirect_urls":{"return_url":"` +
|
||||
redirectURI + `","cancel_url":"` + cancelURI + `"}}`))
|
||||
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/payment"), buf)
|
||||
if err != nil {
|
||||
return &PaymentResponse{}, err
|
||||
|
@ -68,7 +68,7 @@ func (c *Client) CreatePayment(p Payment) (*CreatePaymentResp, error) {
|
|||
// ExecuteApprovedPayment - Use this call to execute (complete) a PayPal payment that has been approved by the payer. You can optionally update transaction information when executing the payment by passing in one or more transactions.
|
||||
// Endpoint: POST /v1/payments/payment/paymentID/execute
|
||||
func (c *Client) ExecuteApprovedPayment(paymentID string, payerID string) (*ExecuteResponse, error) {
|
||||
buf := bytes.NewBuffer([]byte("{\"payer_id\":\"" + payerID + "\"}"))
|
||||
buf := bytes.NewBuffer([]byte(`{"payer_id":"` + payerID + `"}`))
|
||||
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/payment/"+paymentID+"/execute"), buf)
|
||||
if err != nil {
|
||||
return &ExecuteResponse{}, err
|
||||
|
|
Loading…
Reference in New Issue
Block a user