Get rid of escape characters

This commit is contained in:
Oleg Kovalov 2018-10-13 23:45:06 +02:00
parent f7201fdd87
commit f04460162e
3 changed files with 8 additions and 8 deletions

View File

@ -27,7 +27,7 @@ func (c *Client) GetAuthorization(authID string) (*Authorization, error) {
func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture bool) (*Capture, error) { func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture bool) (*Capture, error) {
isFinalStr := strconv.FormatBool(isFinalCapture) 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) req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/authorization/"+authID+"/capture"), buf)
if err != nil { if err != nil {
return &Capture{}, err return &Capture{}, err
@ -56,7 +56,7 @@ func (c *Client) VoidAuthorization(authID string) (*Authorization, error) {
// PayPal recommends to reauthorize payment after ~3 days // PayPal recommends to reauthorize payment after ~3 days
// Endpoint: POST /v1/payments/authorization/ID/reauthorize // Endpoint: POST /v1/payments/authorization/ID/reauthorize
func (c *Client) ReauthorizeAuthorization(authID string, a *Amount) (*Authorization, error) { 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) req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/authorization/"+authID+"/reauthorize"), buf)
if err != nil { if err != nil {
return &Authorization{}, err return &Authorization{}, err

View File

@ -46,7 +46,7 @@ func (c *Client) CreateBillingPlan(plan BillingPlan) (*CreateBillingResp, error)
// By default, a new plan is not activated // By default, a new plan is not activated
// Endpoint: PATCH /v1/payments/billing-plans/ // Endpoint: PATCH /v1/payments/billing-plans/
func (c *Client) ActivatePlan(planID string) error { 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) req, err := http.NewRequest("PATCH", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-plans/"+planID), buf)
if err != nil { if err != nil {
return err return err

View File

@ -22,10 +22,10 @@ type CreatePaymentResp struct {
// CreatePayment is more common function for any kind of payment // CreatePayment is more common function for any kind of payment
// Endpoint: POST /v1/payments/payment // Endpoint: POST /v1/payments/payment
func (c *Client) CreateDirectPaypalPayment(amount Amount, redirectURI string, cancelURI string, description string) (*PaymentResponse, error) { func (c *Client) CreateDirectPaypalPayment(amount Amount, redirectURI string, cancelURI string, description string) (*PaymentResponse, error) {
buf := bytes.NewBuffer([]byte("{\"intent\":\"sale\",\"payer\":{\"payment_method\":\"paypal\"}," + buf := bytes.NewBuffer([]byte(`{"intent":"sale","payer":{"payment_method":"paypal"},` +
"\"transactions\":[{\"amount\":{\"total\":\"" + amount.Total + `"transactions":[{"amount":{"total":"` + amount.Total +
"\",\"currency\":\"" + amount.Currency + "\"},\"description\":\"" + description + "\"}],\"redirect_urls\":{\"return_url\":\"" + `","currency":"` + amount.Currency + `"},"description":"` + description + `"}],"redirect_urls":{"return_url":"` +
redirectURI + "\",\"cancel_url\":\"" + cancelURI + "\"}}")) redirectURI + `","cancel_url":"` + cancelURI + `"}}`))
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/payment"), buf) req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/payment"), buf)
if err != nil { if err != nil {
return &PaymentResponse{}, err 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. // 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 // Endpoint: POST /v1/payments/payment/paymentID/execute
func (c *Client) ExecuteApprovedPayment(paymentID string, payerID string) (*ExecuteResponse, error) { 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) req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/payment/"+paymentID+"/execute"), buf)
if err != nil { if err != nil {
return &ExecuteResponse{}, err return &ExecuteResponse{}, err