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

Add card clone adapter #80

Merged
merged 1 commit into from
Mar 28, 2024
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
7 changes: 7 additions & 0 deletions adapter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,13 @@ type UpdateStoredCardRequest struct {
ExpireMonth string `json:"expireMonth,omitempty"`
}

type CloneStoredCardRequest struct {
SourceCardUserKey string `json:"sourceCardUserKey"`
SourceCardToken string `json:"sourceCardToken"`
TargetCardUserKey string `json:"targetCardUserKey,omitempty"`
TargetMerchantId int64 `json:"targetMerchantId"`
}

type DeleteStoredCardRequest struct {
CardUserKey string `json:"cardUserKey,omitempty"`
CardToken string `json:"cardToken,omitempty"`
Expand Down
16 changes: 16 additions & 0 deletions adapter/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,22 @@ func (api *Payment) UpdateStoredCard(ctx context.Context, request UpdateStoredCa
return response.Data, nil
}

func (api *Payment) CloneStoredCard(ctx context.Context, request CloneStoredCardRequest) (*StoredCardResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/cards/clone", request)

if err != nil {
return nil, err
}

response := &Response[StoredCardResponse]{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return nil, err
}

return response.Data, nil
}

func (api *Payment) DeleteStoredCard(ctx context.Context, request DeleteStoredCardRequest) error {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/cards/delete", request)
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions tests/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,20 @@ func TestPayment_UpdateStoredCard(t *testing.T) {
}
}

func TestPayment_CloneStoredCard(t *testing.T) {
request := adapter.CloneStoredCardRequest{
SourceCardUserKey: "6bcbac4b-6460-418d-b060-2d9896c08156",
SourceCardToken: "aa57f470-7423-449e-87b7-afb1fba151fb",
TargetMerchantId: 1,
}
res, err := paymentClient.Payment.CloneStoredCard(context.Background(), request)
_, _ = spew.Printf("%#v\n", res)

if err != nil {
t.Errorf("Error %s", err)
}
}

func TestPayment_DeleteStoredCard(t *testing.T) {
request := adapter.DeleteStoredCardRequest{
CardUserKey: "d94018bb-baa9-4418-84f8-760942f669af",
Expand Down
Loading