-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c27e83
commit 1e90ff2
Showing
4 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package adapter | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
type BkmExpress struct { | ||
Client *Client | ||
} | ||
|
||
func (api *BkmExpress) Init(ctx context.Context, request InitBkmExpressRequest) (*InitBkmExpressResponse, error) { | ||
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/bkm-express/init", request) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
response := &Response[InitBkmExpressResponse]{} | ||
err = api.Client.Do(ctx, newRequest, response) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return response.Data, nil | ||
} | ||
|
||
func (api *BkmExpress) Complete(ctx context.Context, request CompleteBkmExpressRequest) (*PaymentResponse, error) { | ||
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/bkm-express/complete", request) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
response := &Response[PaymentResponse]{} | ||
err = api.Client.Do(ctx, newRequest, response) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return response.Data, nil | ||
} | ||
|
||
func (api *BkmExpress) RetrievePayment(ctx context.Context, ticketId string) error { | ||
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("/payment/v1/bkm-express/payments/%s", ticketId), nil) | ||
if err != nil { | ||
return fmt.Errorf("failed to create new request: %w", err) | ||
} | ||
response := &Void{} | ||
Check failure on line 48 in adapter/bkm_express.go GitHub Actions / build
|
||
|
||
err = api.Client.Do(ctx, newRequest, response) | ||
if err != nil { | ||
return fmt.Errorf("request failed: %w", err) | ||
} | ||
if response == nil { | ||
Check failure on line 54 in adapter/bkm_express.go GitHub Actions / build
|
||
return fmt.Errorf("empty response") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package tests | ||
|
||
import ( | ||
"context" | ||
"github.com/craftgate/craftgate-go-client/adapter" | ||
craftgate "github.com/craftgate/craftgate-go-client/adapter" | ||
"github.com/davecgh/go-spew/spew" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
var bkmExpressClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io") | ||
|
||
func TestBkm_Express_Init(t *testing.T) { | ||
request := adapter.InitBkmExpressRequest{ | ||
Price: 1.25, | ||
PaidPrice: 1.25, | ||
Currency: craftgate.Currency_TRY, | ||
PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION, | ||
ConversationId: "foo-bar", | ||
Items: []craftgate.PaymentItem{ | ||
{ | ||
Name: "Item 1", | ||
Price: 1, | ||
ExternalId: "1", | ||
}, | ||
{ | ||
Name: "Item 2", | ||
Price: 0.25, | ||
ExternalId: "2", | ||
}, | ||
}, | ||
} | ||
res, err := bkmExpressClient.BkmExpress.Init(context.Background(), request) | ||
_, _ = spew.Printf("%#v\n", res) | ||
|
||
if err != nil { | ||
t.Errorf("Error %s", err) | ||
} | ||
} | ||
|
||
func TestBkm_Express_Complete(t *testing.T) { | ||
request := adapter.CompleteBkmExpressRequest{ | ||
Status: true, | ||
Message: "İşlem Başarılı", | ||
TicketId: "404308dcfdc163-0545-46d7-8f86-5a11718e56ec", | ||
} | ||
|
||
res, err := bkmExpressClient.BkmExpress.Complete(context.Background(), request) | ||
|
||
require.NotNil(t, res.AuthCode) | ||
require.NotNil(t, res.HostReference) | ||
if err != nil { | ||
t.Errorf("Error %s", err) | ||
} | ||
} | ||
|
||
func TestBkm_Express_RetrievePayment(t *testing.T) { | ||
err := bkmExpressClient.BkmExpress.RetrievePayment(context.Background(), "dcfdc163-0545-46d7-8f86-5a11718e56ec") | ||
if err != nil { | ||
t.Fatalf("RetrievePayment failed: %v", err) | ||
} | ||
} |