-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Juzdan integration to Go CLient
- Loading branch information
1 parent
2c94c5c
commit f7effab
Showing
3 changed files
with
127 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,41 @@ | ||
package adapter | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
type Juzdan struct { | ||
Client *Client | ||
} | ||
|
||
func (api *Juzdan) InitJuzdanPayment(ctx context.Context, request InitJuzdanPaymentRequest) (*InitJuzdanPaymentResponse, error) { | ||
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/juzdan-payments/init", request) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
response := &Response[InitJuzdanPaymentResponse]{} | ||
err = api.Client.Do(ctx, newRequest, response) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return response.Data, nil | ||
} | ||
|
||
func (api *Juzdan) RetrieveJuzdanPayment(ctx context.Context, referenceId string) (*PaymentResponse, error) { | ||
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("/installment/v1/bins/%s", referenceId), nil) | ||
|
||
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 | ||
} |
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,58 @@ | ||
package tests | ||
|
||
import ( | ||
"context" | ||
"github.com/craftgate/craftgate-go-client/adapter" | ||
craftgate "github.com/craftgate/craftgate-go-client/adapter" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
var juzdanClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io") | ||
|
||
func Test_InitJuzdanPayment(t *testing.T) { | ||
request := adapter.InitJuzdanPaymentRequest{ | ||
price: 1.25, | ||
paidPrice: 1.25, | ||
currency: craftgate.Currency_TRY, | ||
paymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION, | ||
conversationId: "foo-bar", | ||
externalId: "115", | ||
callbackUrl: "www.test.com", | ||
paymentPhase: craftgate.PaymentPhase_AUTH, | ||
paymentChannel: "test", | ||
buyerMemberId: 1, | ||
bankOrderId: "test", | ||
Items: []craftgate.PaymentItem{ | ||
{ | ||
Name: "Item 1", | ||
Price: 1, | ||
ExternalId: "1", | ||
}, | ||
{ | ||
Name: "Item 2", | ||
Price: 0.25, | ||
ExternalId: "2", | ||
}, | ||
}, | ||
clientType: craftgate.ClientType.W, | ||
loanCampaignId: 1, | ||
} | ||
|
||
res, err := juzdanClient.Juzdan.InitJuzdanPayment(context.Background(), request) | ||
|
||
require.NotNil(t, res.JuzdanQrUrl) | ||
require.NotNil(t, res.ReferenceId) | ||
if err != nil { | ||
t.Errorf("Error %s", err) | ||
} | ||
} | ||
|
||
func Test_RetrieveJuzdanPayment(t *testing.T) { | ||
res, err := juzdanClient.Juzdan.RetrieveJuzdanPayment(context.Background(), "test-reference-id") | ||
_, _ = spew.Printf("%#v\n", res) | ||
|
||
if err != nil { | ||
t.Errorf("Error %s", err) | ||
} | ||
} |