Skip to content

Commit 8e38113

Browse files
authored
Merge pull request #115 from plutov/roopakv/fix_auth_capture
Fix payment capture API
2 parents c0ae3c0 + fee7108 commit 8e38113

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

Diff for: authorization.go

+7-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"fmt"
66
"net/http"
7-
"strconv"
87
)
98

109
// GetAuthorization returns an authorization by ID
@@ -24,20 +23,17 @@ func (c *Client) GetAuthorization(authID string) (*Authorization, error) {
2423

2524
// CaptureAuthorization captures and process an existing authorization.
2625
// To use this method, the original payment must have Intent set to "authorize"
27-
// Endpoint: POST /v2/payments/authorization/ID/capture
28-
func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture bool) (*Capture, error) {
29-
isFinalStr := strconv.FormatBool(isFinalCapture)
30-
31-
buf := bytes.NewBuffer([]byte(`{"amount":{"currency":"` + a.Currency + `,"total":"` + a.Total + `"},"is_final_capture":` + isFinalStr + `}`))
32-
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/authorization/"+authID+"/capture"), buf)
33-
capture := &Capture{}
26+
// Endpoint: POST /v2/payments/authorizations/ID/capture
27+
func (c *Client) CaptureAuthorization(authID string, paymentCaptureRequest *PaymentCaptureRequest) (*PaymentCaptureResponse, error) {
28+
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/authorizations/"+authID+"/capture"), paymentCaptureRequest)
29+
paymentCaptureResponse := &PaymentCaptureResponse{}
3430

3531
if err != nil {
36-
return capture, err
32+
return paymentCaptureResponse, err
3733
}
3834

39-
err = c.SendWithAuth(req, capture)
40-
return capture, err
35+
err = c.SendWithAuth(req, paymentCaptureResponse)
36+
return paymentCaptureResponse, err
4137
}
4238

4339
// VoidAuthorization voids a previously authorized payment

Diff for: types.go

+36
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,42 @@ type (
162162
ApplicationContext ApplicationContext `json:"application_context,omitempty"`
163163
}
164164

165+
// https://developer.paypal.com/docs/api/payments/v2/#definition-platform_fee
166+
PlatformFee struct {
167+
Amount *Money `json:"amount,omitempty"`
168+
Payee *PayeeForOrders `json:"payee,omitempty"`
169+
}
170+
171+
// https://developer.paypal.com/docs/api/payments/v2/#definition-payment_instruction
172+
PaymentInstruction struct {
173+
PlatformFees []PlatformFee `json:"platform_fees,omitempty"`
174+
DisbursementMode string `json:"disbursement_mode,omitempty"`
175+
}
176+
177+
// https://developer.paypal.com/docs/api/payments/v2/#authorizations_capture
178+
PaymentCaptureRequest struct {
179+
InvoiceID string `json:"invoice_id,omitempty"`
180+
NoteToPayer string `json:"note_to_payer,omitempty"`
181+
SoftDescriptor string `json:"soft_descriptor,omitempty"`
182+
Amount *Money `json:"amount,omitempty"`
183+
FinalCapture bool `json:"final_capture,omitempty"`
184+
}
185+
186+
// https://developer.paypal.com/docs/api/payments/v2/#definition-capture_status_details
187+
CaptureStatusDetails struct {
188+
Reason string `json:"reason,omitempty"`
189+
}
190+
191+
PaymentCaptureResponse struct {
192+
Status string `json:"status,omitempty"`
193+
StatusDetails *CaptureStatusDetails `json:"status_details,omitempty"`
194+
ID string `json:"id,omitempty"`
195+
Amount *Money `json:"amount,omitempty"`
196+
InvoiceID string `json:"invoice_id,omitempty"`
197+
FinalCapture bool `json:"final_capture,omitempty"`
198+
DisbursementMode string `json:"disbursement_mode,omitempty"`
199+
}
200+
165201
// CaptureOrderRequest - https://developer.paypal.com/docs/api/orders/v2/#orders_capture
166202
CaptureOrderRequest struct {
167203
PaymentSource *PaymentSource `json:"payment_source"`

0 commit comments

Comments
 (0)