Skip to content

Commit

Permalink
Add card clone adapter (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
abalikci committed Mar 28, 2024
1 parent 57ca2b4 commit 9ce0dd0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
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

0 comments on commit 9ce0dd0

Please sign in to comment.