Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): add Simulate Return Payment endpoint #119

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 87
configured_endpoints: 88
2 changes: 2 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,15 @@ Response Types:
- <a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#Payment">Payment</a>
- <a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#PaymentNewResponse">PaymentNewResponse</a>
- <a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#PaymentSimulateReleaseResponse">PaymentSimulateReleaseResponse</a>
- <a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#PaymentSimulateReturnResponse">PaymentSimulateReturnResponse</a>

Methods:

- <code title="post /payments">client.Payments.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#PaymentService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#PaymentNewParams">PaymentNewParams</a>) (<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#PaymentNewResponse">PaymentNewResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /payments/{payment_token}">client.Payments.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#PaymentService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, paymentToken <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#Payment">Payment</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /payments">client.Payments.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#PaymentService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, query <a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#PaymentListParams">PaymentListParams</a>) (<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go/internal/shared">shared</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go/internal/shared#CursorPage">CursorPage</a>[<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#Payment">Payment</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="post /simulate/payments/release">client.Payments.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#PaymentService.SimulateRelease">SimulateRelease</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#PaymentSimulateReleaseParams">PaymentSimulateReleaseParams</a>) (<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#PaymentSimulateReleaseResponse">PaymentSimulateReleaseResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="post /simulate/payments/return">client.Payments.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#PaymentService.SimulateReturn">SimulateReturn</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#PaymentSimulateReturnParams">PaymentSimulateReturnParams</a>) (<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#PaymentSimulateReturnResponse">PaymentSimulateReturnResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

# ThreeDS

Expand Down
45 changes: 45 additions & 0 deletions payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ func (r *PaymentService) SimulateRelease(ctx context.Context, body PaymentSimula
return
}

// Simulates a return of a Payment.
func (r *PaymentService) SimulateReturn(ctx context.Context, body PaymentSimulateReturnParams, opts ...option.RequestOption) (res *PaymentSimulateReturnResponse, err error) {
opts = append(r.Options[:], opts...)
path := "simulate/payments/return"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}

type Payment struct {
Direction PaymentDirection `json:"direction,required"`
Method PaymentMethod `json:"method,required"`
Expand Down Expand Up @@ -200,6 +208,34 @@ const (
PaymentSimulateReleaseResponseResultDeclined PaymentSimulateReleaseResponseResult = "DECLINED"
)

type PaymentSimulateReturnResponse struct {
DebuggingRequestID string `json:"debugging_request_id" format:"uuid"`
Result PaymentSimulateReturnResponseResult `json:"result"`
TransactionEventToken string `json:"transaction_event_token" format:"uuid"`
JSON paymentSimulateReturnResponseJSON
}

// paymentSimulateReturnResponseJSON contains the JSON metadata for the struct
// [PaymentSimulateReturnResponse]
type paymentSimulateReturnResponseJSON struct {
DebuggingRequestID apijson.Field
Result apijson.Field
TransactionEventToken apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *PaymentSimulateReturnResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

type PaymentSimulateReturnResponseResult string

const (
PaymentSimulateReturnResponseResultApproved PaymentSimulateReturnResponseResult = "APPROVED"
PaymentSimulateReturnResponseResultDeclined PaymentSimulateReturnResponseResult = "DECLINED"
)

type PaymentNewParams struct {
Amount param.Field[int64] `json:"amount,required"`
ExternalBankAccountToken param.Field[string] `json:"external_bank_account_token,required" format:"uuid"`
Expand Down Expand Up @@ -292,3 +328,12 @@ type PaymentSimulateReleaseParams struct {
func (r PaymentSimulateReleaseParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type PaymentSimulateReturnParams struct {
PaymentToken param.Field[string] `json:"payment_token,required" format:"uuid"`
ReturnReasonCode param.Field[string] `json:"return_reason_code"`
}

func (r PaymentSimulateReturnParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
21 changes: 21 additions & 0 deletions payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,24 @@ func TestPaymentSimulateRelease(t *testing.T) {
t.Fatalf("err should be nil: %s", err.Error())
}
}

func TestPaymentSimulateReturnWithOptionalParams(t *testing.T) {
if !testutil.CheckTestServer(t) {
return
}
client := lithic.NewClient(
option.WithBaseURL("http://127.0.0.1:4010"),
option.WithAPIKey("APIKey"),
)
_, err := client.Payments.SimulateReturn(context.TODO(), lithic.PaymentSimulateReturnParams{
PaymentToken: lithic.F("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"),
ReturnReasonCode: lithic.F("string"),
})
if err != nil {
var apierr *lithic.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}