diff --git a/.stats.yml b/.stats.yml index 27c1472..2dc4a08 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 87 +configured_endpoints: 88 diff --git a/api.md b/api.md index 553c81f..f934c34 100644 --- a/api.md +++ b/api.md @@ -331,6 +331,7 @@ Response Types: - lithic.Payment - lithic.PaymentNewResponse - lithic.PaymentSimulateReleaseResponse +- lithic.PaymentSimulateReturnResponse Methods: @@ -338,6 +339,7 @@ Methods: - client.Payments.Get(ctx context.Context, paymentToken string) (lithic.Payment, error) - client.Payments.List(ctx context.Context, query lithic.PaymentListParams) (shared.CursorPage[lithic.Payment], error) - client.Payments.SimulateRelease(ctx context.Context, body lithic.PaymentSimulateReleaseParams) (lithic.PaymentSimulateReleaseResponse, error) +- client.Payments.SimulateReturn(ctx context.Context, body lithic.PaymentSimulateReturnParams) (lithic.PaymentSimulateReturnResponse, error) # ThreeDS diff --git a/payment.go b/payment.go index 73c52a9..c86af8a 100644 --- a/payment.go +++ b/payment.go @@ -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"` @@ -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"` @@ -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) +} diff --git a/payment_test.go b/payment_test.go index f696ea9..24a73b7 100644 --- a/payment_test.go +++ b/payment_test.go @@ -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()) + } +}