Skip to content

Commit

Permalink
added payment samples
Browse files Browse the repository at this point in the history
  • Loading branch information
reywyn committed Aug 15, 2022
1 parent a7cefff commit 901b628
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 25 deletions.
8 changes: 4 additions & 4 deletions adapter/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ type InitCheckoutPaymentRequest struct {
ClientIp string `json:"clientIp,omitempty"`
PaymentPhase model.PaymentPhase `json:"paymentPhase,omitempty"`
PaymentChannel string `json:"paymentChannel,omitempty"`
EnabledPaymentMethods []model.PaymentMethod `json:"enabledPaymentMethods"`
EnabledPaymentMethods []model.PaymentMethod `json:"enabledPaymentMethods,omitempty"`
MasterpassGsmNumber string `json:"masterpassGsmNumber,omitempty"`
MasterpassUserId string `json:"masterpassUserId,omitempty"`
CardUserKey string `json:"cardUserKey,omitempty"`
Expand Down Expand Up @@ -214,7 +214,7 @@ type InitGarantiPayPaymentRequest struct {
BuyerMemberId int64 `json:"buyerMemberId,omitempty"`
BankOrderId string `json:"bankOrderId,omitempty"`
Items []model.PaymentItem `json:"items"`
Installments []GarantiPayInstallment `json:"installments"`
Installments []GarantiPayInstallment `json:"installments,omitempty"`
}

type GarantiPayInstallment struct {
Expand Down Expand Up @@ -323,8 +323,8 @@ type UpdateStoredCardRequest struct {
}

type DeleteStoredCardRequest struct {
cardUserKey string `schema:"cardUserKey,omitempty"`
cardToken string `schema:"cardToken,omitempty"`
CardUserKey string `schema:"cardUserKey,omitempty"`
CardToken string `schema:"cardToken,omitempty"`
}

type SearchStoredCardsRequest struct {
Expand Down
170 changes: 149 additions & 21 deletions tests/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestPayment_CreatePayment(t *testing.T) {
Installment: 1,
Currency: model.Currency(model.TRY),
PaymentGroup: model.PaymentGroup(model.LISTING_OR_SUBSCRIPTION),
ConversationId: "abcdef",
ConversationId: "foo-bar",
ExternalId: "115",
Card: model.Card{
CardHolderName: "Card Holder",
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestPayment_Init3DSPayment(t *testing.T) {
Installment: 1,
Currency: model.Currency(model.TRY),
PaymentGroup: model.PaymentGroup(model.LISTING_OR_SUBSCRIPTION),
ConversationId: "abcdef",
ConversationId: "foo-bar",
ExternalId: "115",
Card: model.Card{
CardHolderName: "Card Holder",
Expand Down Expand Up @@ -102,7 +102,9 @@ func TestPayment_Init3DSPayment(t *testing.T) {
}

func TestPayment_Complete3DSPayment(t *testing.T) {
res, err := payment.Complete3DSPayment(adapter.Complete3DSPaymentRequest{})
res, err := payment.Complete3DSPayment(adapter.Complete3DSPaymentRequest{
PaymentId: 123,
})
spew.Printf("%#v\n", res)

if err != nil {
Expand All @@ -111,7 +113,9 @@ func TestPayment_Complete3DSPayment(t *testing.T) {
}

func TestPayment_PostAuthPayment(t *testing.T) {
res, err := payment.PostAuthPayment(123, adapter.PostAuthPaymentRequest{})
res, err := payment.PostAuthPayment(123, adapter.PostAuthPaymentRequest{
PaidPrice: 15.3,
})
spew.Printf("%#v\n", res)

if err != nil {
Expand All @@ -120,7 +124,30 @@ func TestPayment_PostAuthPayment(t *testing.T) {
}

func TestPayment_InitCheckoutPayment(t *testing.T) {
res, err := payment.InitCheckoutPayment(adapter.InitCheckoutPaymentRequest{})
request := adapter.InitCheckoutPaymentRequest{
Price: 1.25,
PaidPrice: 1.25,
BuyerMemberId: 1,
Currency: model.TRY,
PaymentGroup: model.LISTING_OR_SUBSCRIPTION,
PaymentPhase: model.AUTH,
ConversationId: "foo-bar",
ExternalId: "115",
Items: []model.PaymentItem{
{
Name: "Item 1",
Price: 1,
ExternalId: "1",
},
{
Name: "Item 2",
Price: 0.25,
ExternalId: "2",
},
},
CallbackUrl: "www.callback.url",
}
res, err := payment.InitCheckoutPayment(request)
spew.Printf("%#v\n", res)

if err != nil {
Expand All @@ -129,7 +156,7 @@ func TestPayment_InitCheckoutPayment(t *testing.T) {
}

func TestPayment_RetrieveCheckoutPayment(t *testing.T) {
res, err := payment.RetrieveCheckoutPayment("asdfg")
res, err := payment.RetrieveCheckoutPayment("foo-bar")
spew.Printf("%#v\n", res)

if err != nil {
Expand All @@ -138,7 +165,18 @@ func TestPayment_RetrieveCheckoutPayment(t *testing.T) {
}

func TestPayment_CreateDepositPayment(t *testing.T) {
res, err := payment.CreateDepositPayment(adapter.DepositPaymentRequest{})
res, err := payment.CreateDepositPayment(adapter.DepositPaymentRequest{
Price: 100,
BuyerMemberId: 1,
ConversationId: "456d1297-908e-4bd6-a13b-4be31a6e47d5",
Card: model.Card{
CardHolderName: "Haluk Demir",
CardNumber: "5258640000000001",
ExpireYear: "2044",
ExpireMonth: "07",
Cvc: "000",
},
})
spew.Printf("%#v\n", res)

if err != nil {
Expand All @@ -147,7 +185,19 @@ func TestPayment_CreateDepositPayment(t *testing.T) {
}

func TestPayment_Init3DSDepositPayment(t *testing.T) {
res, err := payment.Init3DSDepositPayment(adapter.DepositPaymentRequest{})
res, err := payment.Init3DSDepositPayment(adapter.DepositPaymentRequest{
Price: 100,
BuyerMemberId: 1,
CallbackUrl: "https://www.your-website.com/craftgate-3DSecure-callback",
ConversationId: "456d1297-908e-4bd6-a13b-4be31a6e47d5",
Card: model.Card{
CardHolderName: "Haluk Demir",
CardNumber: "5258640000000001",
ExpireYear: "2044",
ExpireMonth: "07",
Cvc: "000",
},
})
spew.Printf("%#v\n", res)

if err != nil {
Expand All @@ -156,7 +206,9 @@ func TestPayment_Init3DSDepositPayment(t *testing.T) {
}

func TestPayment_Complete3DSDepositPayment(t *testing.T) {
res, err := payment.Complete3DSDepositPayment(adapter.Complete3DSPaymentRequest{})
res, err := payment.Complete3DSDepositPayment(adapter.Complete3DSPaymentRequest{
PaymentId: 1,
})
spew.Printf("%#v\n", res)

if err != nil {
Expand All @@ -165,15 +217,48 @@ func TestPayment_Complete3DSDepositPayment(t *testing.T) {
}

func TestPayment_CreateFundTransferDepositPayment(t *testing.T) {
err := payment.CreateFundTransferDepositPayment(adapter.CreateFundTransferDepositPaymentRequest{})
err := payment.CreateFundTransferDepositPayment(adapter.CreateFundTransferDepositPaymentRequest{
Price: 100,
BuyerMemberId: 1,
ConversationId: "456d1297-908e-4bd6-a13b-4be31a6e47d5",
})

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

func TestPayment_InitGarantiPayPayment(t *testing.T) {
res, err := payment.InitGarantiPayPayment(adapter.InitGarantiPayPaymentRequest{})
res, err := payment.InitGarantiPayPayment(adapter.InitGarantiPayPaymentRequest{
Price: 100,
PaidPrice: 100,
Currency: model.TRY,
PaymentGroup: model.LISTING_OR_SUBSCRIPTION,
ConversationId: "456d1297-908e-4bd6-a13b-4be31a6e47d5",
CallbackUrl: "https://www.your-website.com/craftgate-garantipay-callback",
Items: []model.PaymentItem{
{
Name: "Item 1",
Price: 60,
ExternalId: "1",
},
{
Name: "Item 2",
Price: 40,
ExternalId: "2",
},
},
Installments: []adapter.GarantiPayInstallment{
{
Number: 2,
TotalPrice: 120,
},
{
Number: 3,
TotalPrice: 125,
},
},
})
spew.Printf("%#v\n", res)

if err != nil {
Expand All @@ -182,7 +267,12 @@ func TestPayment_InitGarantiPayPayment(t *testing.T) {
}

func TestPayment_RetrieveLoyalties(t *testing.T) {
res, err := payment.RetrieveLoyalties(adapter.RetrieveLoyaltiesRequest{})
res, err := payment.RetrieveLoyalties(adapter.RetrieveLoyaltiesRequest{
CardNumber: "4043080000000003",
ExpireYear: "2044",
ExpireMonth: "07",
Cvc: "000",
})
spew.Printf("%#v\n", res)

if err != nil {
Expand All @@ -191,7 +281,12 @@ func TestPayment_RetrieveLoyalties(t *testing.T) {
}

func TestPayment_RefundPaymentTransaction(t *testing.T) {
res, err := payment.RefundPaymentTransaction(adapter.RefundPaymentTransactionRequest{})
res, err := payment.RefundPaymentTransaction(adapter.RefundPaymentTransactionRequest{
PaymentTransactionId: 1,
ConversationId: "456d1297-908e-4bd6-a13b-4be31a6e47d5",
RefundPrice: 20,
RefundDestinationType: model.RefundDestinationTypeCARD,
})
spew.Printf("%#v\n", res)

if err != nil {
Expand All @@ -209,7 +304,10 @@ func TestPayment_RetrievePaymentTransactionRefund(t *testing.T) {
}

func TestPayment_RefundPayment(t *testing.T) {
res, err := payment.RefundPayment(adapter.RefundPaymentRequest{})
res, err := payment.RefundPayment(adapter.RefundPaymentRequest{
PaymentId: 1,
RefundDestinationType: model.RefundDestinationTypeCARD,
})
spew.Printf("%#v\n", res)

if err != nil {
Expand All @@ -227,7 +325,13 @@ func TestPayment_RetrievePaymentRefund(t *testing.T) {
}

func TestPayment_StoreCard(t *testing.T) {
res, err := payment.StoreCard(adapter.StoreCardRequest{})
res, err := payment.StoreCard(adapter.StoreCardRequest{
CardHolderName: "Haluk Demir",
CardNumber: "5258640000000001",
ExpireYear: "2044",
ExpireMonth: "07",
CardAlias: "My Card",
})
spew.Printf("%#v\n", res)

if err != nil {
Expand All @@ -236,7 +340,12 @@ func TestPayment_StoreCard(t *testing.T) {
}

func TestPayment_UpdateStoredCard(t *testing.T) {
res, err := payment.UpdateStoredCard(adapter.UpdateStoredCardRequest{})
res, err := payment.UpdateStoredCard(adapter.UpdateStoredCardRequest{
CardUserKey: "fac377f2-ab15-4696-88d2-5e71b27ec378",
CardToken: "11a078c4-3c32-4796-90b1-51ee5517a212",
ExpireYear: "2044",
ExpireMonth: "07",
})
spew.Printf("%#v\n", res)

if err != nil {
Expand All @@ -245,15 +354,26 @@ func TestPayment_UpdateStoredCard(t *testing.T) {
}

func TestPayment_DeleteStoredCard(t *testing.T) {
err := payment.DeleteStoredCard(adapter.DeleteStoredCardRequest{})
err := payment.DeleteStoredCard(adapter.DeleteStoredCardRequest{
CardUserKey: "fac377f2-ab15-4696-88d2-5e71b27ec378",
CardToken: "11a078c4-3c32-4796-90b1-51ee5517a212",
})

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

func TestPayment_SearchStoredCards(t *testing.T) {
res, err := payment.SearchStoredCards(adapter.SearchStoredCardsRequest{})
res, err := payment.SearchStoredCards(adapter.SearchStoredCardsRequest{
CardAlias: "My YKB Card",
CardBankName: "YAPI VE KREDI BANKASI A.S.",
CardBrand: "World",
CardType: model.CREDIT_CARD,
CardAssociation: model.MASTER_CARD,
CardUserKey: "c115ecdf-0afc-4d83-8a1b-719c2af19cbd",
CardToken: "d9b19d1a-243c-43dc-a498-add08162df72",
})
spew.Printf("%#v\n", res)

if err != nil {
Expand All @@ -262,7 +382,10 @@ func TestPayment_SearchStoredCards(t *testing.T) {
}

func TestPayment_ApprovePaymentTransactions(t *testing.T) {
res, err := payment.ApprovePaymentTransactions(adapter.PaymentTransactionsApprovalRequest{})
res, err := payment.ApprovePaymentTransactions(adapter.PaymentTransactionsApprovalRequest{
PaymentTransactionIds: []int64{1, 2},
IsTransactional: true,
})
spew.Printf("%#v\n", res)

if err != nil {
Expand All @@ -271,7 +394,10 @@ func TestPayment_ApprovePaymentTransactions(t *testing.T) {
}

func TestPayment_DisapprovePaymentTransactions(t *testing.T) {
res, err := payment.DisapprovePaymentTransactions(adapter.PaymentTransactionsApprovalRequest{})
res, err := payment.DisapprovePaymentTransactions(adapter.PaymentTransactionsApprovalRequest{
PaymentTransactionIds: []int64{1, 2},
IsTransactional: true,
})
spew.Printf("%#v\n", res)

if err != nil {
Expand All @@ -280,7 +406,9 @@ func TestPayment_DisapprovePaymentTransactions(t *testing.T) {
}

func TestPayment_CheckMasterpassUser(t *testing.T) {
res, err := payment.CheckMasterpassUser(adapter.CheckMasterpassUserRequest{})
res, err := payment.CheckMasterpassUser(adapter.CheckMasterpassUserRequest{
MasterpassGsmNumber: "903000000000",
})
spew.Printf("%#v\n", res)

if err != nil {
Expand Down

0 comments on commit 901b628

Please sign in to comment.