From 6a522c7a96827bf4460d3ee3b019bb3855de6789 Mon Sep 17 00:00:00 2001 From: Emre INAL <9061788+reywyn@users.noreply.github.com> Date: Fri, 6 Oct 2023 10:49:25 +0300 Subject: [PATCH 01/30] Adds paymentId to 3DS init and GarantiPay init (#51) --- adapter/model.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adapter/model.go b/adapter/model.go index 5afb0cd..1e2a642 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -706,6 +706,7 @@ type PaymentTransactionResponse struct { type Init3DSPaymentResponse struct { HtmlContent *string `json:"htmlContent"` + PaymentId *int64 `json:"paymentId"` } type InitCheckoutPaymentResponse struct { @@ -921,6 +922,7 @@ type GarantiPayInstallment struct { type InitGarantiPayPaymentResponse struct { HtmlContent *string `json:"htmlContent"` + PaymentId *int64 `json:"paymentId"` } type RetrieveLoyaltiesResponse struct { From 85fe5db979523a2f33d8506f88e17211374ad3cf Mon Sep 17 00:00:00 2001 From: Emre INAL <9061788+reywyn@users.noreply.github.com> Date: Fri, 6 Oct 2023 10:51:40 +0300 Subject: [PATCH 02/30] Adds PosApm endpoints and refactors model names (#37) --- README.md | 4 +- adapter/craftgate.go | 2 +- adapter/model.go | 448 +++++++++++++++++++---------- adapter/payment.go | 34 +++ go.mod | 2 +- tests/file_reporting_test.go | 30 +- tests/fraud_test.go | 88 +++--- tests/hook_test.go | 8 +- tests/installment_test.go | 2 +- tests/masterpass_test.go | 152 +++++----- tests/onboarding_test.go | 10 +- tests/pay_by_link_test.go | 98 +++---- tests/payment_reporting_test.go | 128 ++++----- tests/payment_test.go | 111 ++++--- tests/settlement_reporting_test.go | 2 +- tests/settlement_test.go | 18 +- tests/wallet_test.go | 248 ++++++++-------- 17 files changed, 799 insertions(+), 586 deletions(-) diff --git a/README.md b/README.md index 34a1708..e20bb8c 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ client, _ := craftgate.New("", "", "https://api.c request := craftgate.SearchInstallmentsRequest{ BinNumber: "487074", Price: 100, - Currency: craftgate.TRY, + Currency: craftgate.Currency_TRY, } res, err := client.Installment.SearchInstallments(context.Background(), request) @@ -61,7 +61,7 @@ client, _ := craftgate.New("", "", "https://sandb request := craftgate.CreatePaymentRequest{ Price: 100, PaidPrice: 100, - Currency: craftgate.TRY, + Currency: craftgate.Currency_TRY, ... } diff --git a/adapter/craftgate.go b/adapter/craftgate.go index 0bc0841..9f5b994 100644 --- a/adapter/craftgate.go +++ b/adapter/craftgate.go @@ -109,8 +109,8 @@ func newClient(apiKey, secretKey string) *Client { client.Installment = &Installment{Client: client} client.Payment = &Payment{Client: client} - client.Onboarding = &Onboarding{Client: client} client.PaymentReporting = &PaymentReporting{Client: client} + client.Onboarding = &Onboarding{Client: client} client.PayByLink = &PayByLink{Client: client} client.Wallet = &Wallet{Client: client} client.Settlement = &Settlement{Client: client} diff --git a/adapter/model.go b/adapter/model.go index 1e2a642..65a97c6 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -5,6 +5,7 @@ import "time" type PaymentType string type ApmType string type PaymentProvider string +type PosApmPaymentProvider string type PaymentStatus string type PaymentSource string type PaymentGroup string @@ -20,6 +21,7 @@ type RefundStatus string type RefundType string type ApprovalStatus string type Status string +type OnboardingStatus string type MemberType string type SettlementType string type SettlementEarningsDestination string @@ -29,11 +31,16 @@ type TransactionPayoutStatus string type WalletTransactionRefundTransactionType string type FraudAction string type FraudCheckStatus string +type AdditionalAction string type ApmAdditionalAction string type ReportFileType string type WalletTransactionType string type WebhookEventType string type WebhookStatus string +type PosStatus string +type PosIntegrator string +type PosUserType string +type PosOperationType string type FileStatus string type AccountOwner string type PayoutAccountType string @@ -50,93 +57,102 @@ const ( // payment type declaration const ( - CARD_PAYMENT PaymentType = "CARD_PAYMENT" - WALLET_PAYMENT PaymentType = "WALLET_PAYMENT" - CARD_AND_WALLET_PAYMENT PaymentType = "CARD_AND_WALLET_PAYMENT" - DEPOSIT_PAYMENT PaymentType = "DEPOSIT_PAYMENT" - APM = "APM" + PaymentType_CARD_PAYMENT PaymentType = "CARD_PAYMENT" + PaymentType_WALLET_PAYMENT PaymentType = "WALLET_PAYMENT" + PaymentType_CARD_AND_WALLET_PAYMENT PaymentType = "CARD_AND_WALLET_PAYMENT" + PaymentType_DEPOSIT_PAYMENT PaymentType = "DEPOSIT_PAYMENT" + PaymentType_BANK_TRANSFER PaymentType = "BANK_TRANSFER" + PaymentType_APM PaymentType = "APM" ) +// apm type declaration const ( - ApmTypePAPARA ApmType = "PAPARA" - ApmTypePAYONEER ApmType = "PAYONEER" - ApmTypeSODEXO ApmType = "SODEXO" - ApmTypeEDENRED ApmType = "EDENRED" - ApmTypeEDENRED_GIFT ApmType = "EDENRED_GIFT" - ApmTypePAYPAL ApmType = "PAYPAL" - ApmTypeKLARNA ApmType = "KLARNA" - ApmTypeAFTERPAY ApmType = "AFTERPAY" - ApmTypeKASPI ApmType = "KASPI" - ApmTypeSTRIPE ApmType = "STRIPE" - ApmTypeFUND_TRANSFER ApmType = "FUND_TRANSFER" - ApmTypeCASH_ON_DELIVERY ApmType = "CASH_ON_DELIVERY" + ApmType_PAPARA ApmType = "PAPARA" + ApmType_PAYONEER ApmType = "PAYONEER" + ApmType_SODEXO ApmType = "SODEXO" + ApmType_EDENRED ApmType = "EDENRED" + ApmType_EDENRED_GIFT ApmType = "EDENRED_GIFT" + ApmType_PAYPAL ApmType = "PAYPAL" + ApmType_KLARNA ApmType = "KLARNA" + ApmType_AFTERPAY ApmType = "AFTERPAY" + ApmType_KASPI ApmType = "KASPI" + ApmType_STRIPE ApmType = "STRIPE" + ApmType_FUND_TRANSFER ApmType = "FUND_TRANSFER" + ApmType_CASH_ON_DELIVERY ApmType = "CASH_ON_DELIVERY" ) // payment provider declaration const ( - BANK PaymentProvider = "BANK" - CG_WALLET PaymentProvider = "CG_WALLET" - MASTERPASS PaymentProvider = "MASTERPASS" - GARANTI_PAY PaymentProvider = "GARANTI_PAY" - YKB_WORLD_PAY PaymentProvider = "YKB_WORLD_PAY" - PAPARA PaymentProvider = "PAPARA" - PAYONEER PaymentProvider = "PAYONEER" - SODEXO PaymentProvider = "SODEXO" - EDENRED PaymentProvider = "EDENRED" - ALIPAY PaymentProvider = "ALIPAY" - PAYPAL PaymentProvider = "PAYPAL" - KLARNA PaymentProvider = "KLARNA" - AFTERPAY PaymentProvider = "AFTERPAY" - KASPI PaymentProvider = "KASPI" - APPLEPAY PaymentProvider = "APPLEPAY" - GOOGLEPAY PaymentProvider = "GOOGLEPAY" - HEPSIPAY PaymentProvider = "HEPSIPAY" - STRIPE PaymentProvider = "STRIPE" - OFFLINE PaymentProvider = "OFFLINE" + PaymentProvider_BANK PaymentProvider = "BANK" + PaymentProvider_CG_WALLET PaymentProvider = "CG_WALLET" + PaymentProvider_MASTERPASS PaymentProvider = "MASTERPASS" + PaymentProvider_GARANTI_PAY PaymentProvider = "GARANTI_PAY" + PaymentProvider_YKB_WORLD_PAY PaymentProvider = "YKB_WORLD_PAY" + PaymentProvider_PAPARA PaymentProvider = "PAPARA" + PaymentProvider_PAYONEER PaymentProvider = "PAYONEER" + PaymentProvider_SODEXO PaymentProvider = "SODEXO" + PaymentProvider_EDENRED PaymentProvider = "EDENRED" + PaymentProvider_ALIPAY PaymentProvider = "ALIPAY" + PaymentProvider_PAYPAL PaymentProvider = "PAYPAL" + PaymentProvider_KLARNA PaymentProvider = "KLARNA" + PaymentProvider_AFTERPAY PaymentProvider = "AFTERPAY" + PaymentProvider_KASPI PaymentProvider = "KASPI" + PaymentProvider_APPLEPAY PaymentProvider = "APPLEPAY" + PaymentProvider_GOOGLEPAY PaymentProvider = "GOOGLEPAY" + PaymentProvider_HEPSIPAY PaymentProvider = "HEPSIPAY" + PaymentProvider_STRIPE PaymentProvider = "STRIPE" + PaymentProvider_OFFLINE PaymentProvider = "OFFLINE" +) + +// pos apm payment provider declaration +const ( + PosApmPaymentProvider_YKB_WORLD_PAY PosApmPaymentProvider = "YKB_WORLD_PAY" + PosApmPaymentProvider_APPLEPAY PosApmPaymentProvider = "APPLEPAY" + PosApmPaymentProvider_GOOGLEPAY PosApmPaymentProvider = "GOOGLEPAY" ) // payment status declaration const ( - FAILURE PaymentStatus = "FAILURE" - SUCCESS PaymentStatus = "SUCCESS" - INIT_THREEDS PaymentStatus = "INIT_THREEDS" - CALLBACK_THREEDS PaymentStatus = "CALLBACK_THREEDS" - WAITING PaymentStatus = "WAITING" + PaymentStatus_FAILURE PaymentStatus = "FAILURE" + PaymentStatus_SUCCESS PaymentStatus = "SUCCESS" + PaymentStatus_INIT_THREEDS PaymentStatus = "INIT_THREEDS" + PaymentStatus_CALLBACK_THREEDS PaymentStatus = "CALLBACK_THREEDS" + PaymentStatus_WAITING PaymentStatus = "WAITING" ) // payment source declaration const ( - API PaymentSource = "API" - CHECKOUT_FORM PaymentSource = "CHECKOUT_FORM" - PAY_BY_LINK PaymentSource = "PAY_BY_LINK" + PaymentSource_API PaymentSource = "API" + PaymentSource_CHECKOUT_FORM PaymentSource = "CHECKOUT_FORM" + PaymentSource_PAY_BY_LINK PaymentSource = "PAY_BY_LINK" ) // currency declaration const ( - TRY Currency = "TRY" - USD Currency = "USD" - EUR Currency = "EUR" - GBP Currency = "GBP" - CNY Currency = "CNY" - ARS Currency = "ARS" - BRL Currency = "BRL" - AED Currency = "AED" - IQD Currency = "IQD" - AZN Currency = "AZN" - KZT Currency = "KZT" + Currency_TRY Currency = "TRY" + Currency_USD Currency = "USD" + Currency_EUR Currency = "EUR" + Currency_GBP Currency = "GBP" + Currency_CNY Currency = "CNY" + Currency_ARS Currency = "ARS" + Currency_BRL Currency = "BRL" + Currency_AED Currency = "AED" + Currency_IQD Currency = "IQD" + Currency_AZN Currency = "AZN" + Currency_KZT Currency = "KZT" ) // payment group declaration const ( - PRODUCT PaymentGroup = "PRODUCT" - LISTING_OR_SUBSCRIPTION PaymentGroup = "LISTING_OR_SUBSCRIPTION" + PaymentGroup_PRODUCT PaymentGroup = "PRODUCT" + PaymentGroup_LISTING_OR_SUBSCRIPTION PaymentGroup = "LISTING_OR_SUBSCRIPTION" ) // payment phase declaration const ( - AUTH PaymentPhase = "AUTH" - PRE_AUTH PaymentPhase = "PRE_AUTH" - POST_AUTH PaymentPhase = "POST_AUTH" + PaymentPhase_AUTH PaymentPhase = "AUTH" + PaymentPhase_PRE_AUTH PaymentPhase = "PRE_AUTH" + PaymentPhase_POST_AUTH PaymentPhase = "POST_AUTH" ) // payment method declaration @@ -158,196 +174,266 @@ const ( // card type declaration const ( - CREDIT_CARD CardType = "CREDIT_CARD" - DEBIT_CARD CardType = "DEBIT_CARD" - PREPAID_CARD CardType = "PREPAID_CARD" + CardType_CREDIT_CARD CardType = "CREDIT_CARD" + CardType_DEBIT_CARD CardType = "DEBIT_CARD" + CardType_PREPAID_CARD CardType = "PREPAID_CARD" ) // card association declaration const ( - VISA CardAssociation = "VISA" - MASTER_CARD CardAssociation = "MASTER_CARD" - AMEX CardAssociation = "AMEX" - TROY CardAssociation = "TROY" - JCB CardAssociation = "JCB" - UNION_PAY CardAssociation = "UNION_PAY" - MAESTRO CardAssociation = "MAESTRO" - DISCOVER CardAssociation = "DISCOVER" - DINERS_CLUB CardAssociation = "DINERS_CLUB" + CardAssociation_VISA CardAssociation = "VISA" + CardAssociation_MASTER_CARD CardAssociation = "MASTER_CARD" + CardAssociation_AMEX CardAssociation = "AMEX" + CardAssociation_TROY CardAssociation = "TROY" + CardAssociation_JCB CardAssociation = "JCB" + CardAssociation_UNION_PAY CardAssociation = "UNION_PAY" + CardAssociation_MAESTRO CardAssociation = "MAESTRO" + CardAssociation_DISCOVER CardAssociation = "DISCOVER" + CardAssociation_DINERS_CLUB CardAssociation = "DINERS_CLUB" ) // card expiry status declaration const ( - EXPIRED CardExpiryStatus = "EXPIRED" - WILL_EXPIRE_NEXT_MONTH CardExpiryStatus = "WILL_EXPIRE_NEXT_MONTH" - NOT_EXPIRED CardExpiryStatus = "NOT_EXPIRED" + CardExpiryStatus_EXPIRED CardExpiryStatus = "EXPIRED" + CardExpiryStatus_WILL_EXPIRE_NEXT_MONTH CardExpiryStatus = "WILL_EXPIRE_NEXT_MONTH" + CardExpiryStatus_NOT_EXPIRED CardExpiryStatus = "NOT_EXPIRED" ) // loyalty type declaration const ( - REWARD_MONEY LoyaltyType = "REWARD_MONEY" - ADDITIONAL_INSTALLMENT LoyaltyType = "ADDITIONAL_INSTALLMENT" - POSTPONING_INSTALLMENT LoyaltyType = "POSTPONING_INSTALLMENT" - EXTRA_POINTS LoyaltyType = "EXTRA_POINTS" - GAINING_MINUTES LoyaltyType = "GAINING_MINUTES" - POSTPONING_STATEMENT LoyaltyType = "POSTPONING_STATEMENT" + LoyaltyType_REWARD_MONEY LoyaltyType = "REWARD_MONEY" + LoyaltyType_ADDITIONAL_INSTALLMENT LoyaltyType = "ADDITIONAL_INSTALLMENT" + LoyaltyType_POSTPONING_INSTALLMENT LoyaltyType = "POSTPONING_INSTALLMENT" + LoyaltyType_EXTRA_POINTS LoyaltyType = "EXTRA_POINTS" + LoyaltyType_GAINING_MINUTES LoyaltyType = "GAINING_MINUTES" + LoyaltyType_POSTPONING_STATEMENT LoyaltyType = "POSTPONING_STATEMENT" ) // payment refund status declaration const ( - NO_REFUND PaymentRefundStatus = "NO_REFUND" - NOT_REFUNDED PaymentRefundStatus = "NOT_REFUNDED" - PARTIAL_REFUNDED PaymentRefundStatus = "PARTIAL_REFUNDED" - FULLY_REFUNDED PaymentRefundStatus = "FULLY_REFUNDED" + PaymentRefundStatus_NO_REFUND PaymentRefundStatus = "NO_REFUND" + PaymentRefundStatus_NOT_REFUNDED PaymentRefundStatus = "NOT_REFUNDED" + PaymentRefundStatus_PARTIAL_REFUNDED PaymentRefundStatus = "PARTIAL_REFUNDED" + PaymentRefundStatus_FULLY_REFUNDED PaymentRefundStatus = "FULLY_REFUNDED" ) // refund status declaration const ( - SuccessRefundStatus RefundStatus = "SUCCESS" - FailureRefundStatus RefundStatus = "FAILURE" + RefundStatus_SUCCESS RefundStatus = "SUCCESS" + RefundStatus_FAILURE RefundStatus = "FAILURE" +) + +// onboarding status declaration +const ( + OnboardingStatus_APPLICATION_REJECTED OnboardingStatus = "APPLICATION_REJECTED" + OnboardingStatus_REGISTERED OnboardingStatus = "REGISTERED" + OnboardingStatus_REGISTER_CONFIRMED OnboardingStatus = "REGISTER_CONFIRMED" + OnboardingStatus_APPLIED OnboardingStatus = "APPLIED" + OnboardingStatus_INTEGRATION OnboardingStatus = "INTEGRATION" + OnboardingStatus_LIVE OnboardingStatus = "LIVE" ) // refund type declaration const ( - CANCEL RefundType = "CANCEL" - REFUND RefundType = "REFUND" + RefundType_CANCEL RefundType = "CANCEL" + RefundType_REFUND RefundType = "REFUND" ) // approval status declaration const ( - SuccessApprovalStatus ApprovalStatus = "SUCCESS" - FailureApprovalStatus ApprovalStatus = "FAILURE" + ApprovalStatus_SUCCESS ApprovalStatus = "SUCCESS" + ApprovalStatus_FAILURE ApprovalStatus = "FAILURE" ) // status declaration const ( - ACTIVE Status = "ACTIVE" - PASSIVE Status = "PASSIVE" + Status_ACTIVE Status = "ACTIVE" + Status_PASSIVE Status = "PASSIVE" ) // member type declaration const ( - PERSONAL MemberType = "PERSONAL" - PRIVATE_COMPANY MemberType = "PRIVATE_COMPANY" - LIMITED_OR_JOINT_STOCK_COMPANY MemberType = "LIMITED_OR_JOINT_STOCK_COMPANY" + MemberType_PERSONAL MemberType = "PERSONAL" + MemberType_PRIVATE_COMPANY MemberType = "PRIVATE_COMPANY" + MemberType_LIMITED_OR_JOINT_STOCK_COMPANY MemberType = "LIMITED_OR_JOINT_STOCK_COMPANY" ) // settlementEarningsDestination type declaration const ( - SettlementEarningsDestinationIBAN SettlementEarningsDestination = "IBAN" - SettlementEarningsDestinationWALLET SettlementEarningsDestination = "WALLET" - SettlementEarningsDestinationCROSS_BORDER SettlementEarningsDestination = "CROSS_BORDER" + SettlementEarningsDestination_IBAN SettlementEarningsDestination = "IBAN" + SettlementEarningsDestination_WALLET SettlementEarningsDestination = "WALLET" + SettlementEarningsDestination_CROSS_BORDER SettlementEarningsDestination = "CROSS_BORDER" ) // refundDestinationType type declaration const ( - RefundDestinationTypePROVIDER RefundDestinationType = "PROVIDER" - RefundDestinationTypeWALLET RefundDestinationType = "WALLET" + RefundDestinationType_PROVIDER RefundDestinationType = "PROVIDER" + RefundDestinationType_WALLET RefundDestinationType = "WALLET" ) // transaction status declaration const ( - WAITING_FOR_APPROVAL TransactionStatus = "WAITING_FOR_APPROVAL" - APPROVED TransactionStatus = "APPROVED" - PAYOUT_STARTED TransactionStatus = "PAYOUT_STARTED" + TransactionStatus_WAITING_FOR_APPROVAL TransactionStatus = "WAITING_FOR_APPROVAL" + TransactionStatus_APPROVED TransactionStatus = "APPROVED" + TransactionStatus_PAYOUT_STARTED TransactionStatus = "PAYOUT_STARTED" ) // transaction payout status declaration const ( - TransactionPayoutStatusCANCELLED TransactionPayoutStatus = "CANCELLED" - TransactionPayoutStatusNO_PAYOUT TransactionPayoutStatus = "NO_PAYOUT" - TransactionPayoutStatusWAITING_FOR_PAYOUT TransactionPayoutStatus = "WAITING_FOR_PAYOUT" - TransactionPayoutStatusPAYOUT_STARTED TransactionPayoutStatus = "PAYOUT_STARTED" - TransactionPayoutStatusPAYOUT_COMPLETED TransactionPayoutStatus = "PAYOUT_COMPLETED" + TransactionPayoutStatus_CANCELLED TransactionPayoutStatus = "CANCELLED" + TransactionPayoutStatus_NO_PAYOUT TransactionPayoutStatus = "NO_PAYOUT" + TransactionPayoutStatus_WAITING_FOR_PAYOUT TransactionPayoutStatus = "WAITING_FOR_PAYOUT" + TransactionPayoutStatus_PAYOUT_STARTED TransactionPayoutStatus = "PAYOUT_STARTED" + TransactionPayoutStatus_PAYOUT_COMPLETED TransactionPayoutStatus = "PAYOUT_COMPLETED" ) // settlement type declaration const ( - SettlementTypeSETTLEMENT SettlementType = "SETTLEMENT" - SettlementTypeBOUNCED_SETTLEMENT SettlementType = "BOUNCED_SETTLEMENT" - SettlementTypeWITHDRAW SettlementType = "WITHDRAW" + SettlementType_SETTLEMENT SettlementType = "SETTLEMENT" + SettlementType_BOUNCED_SETTLEMENT SettlementType = "BOUNCED_SETTLEMENT" + SettlementType_WITHDRAW SettlementType = "WITHDRAW" ) // wallet transaction refund type declaration const ( - PAYMENT WalletTransactionRefundTransactionType = "PAYMENT" - PAYMENT_TX WalletTransactionRefundTransactionType = "PAYMENT_TX" - WALLET_TX WalletTransactionRefundTransactionType = "WALLET_TX" + WalletTransactionRefundCardTransactionType_PAYMENT WalletTransactionRefundTransactionType = "PAYMENT" + WalletTransactionRefundCardTransactionType_PAYMENT_TX WalletTransactionRefundTransactionType = "PAYMENT_TX" + WalletTransactionRefundCardTransactionType_WALLET_TX WalletTransactionRefundTransactionType = "WALLET_TX" ) // fraud action type declaration const ( - BLOCK FraudAction = "BLOCK" - REVIEW FraudAction = "REVIEW" + FraudAction_BLOCK FraudAction = "BLOCK" + FraudAction_REVIEW FraudAction = "REVIEW" ) // fraud check status type declaration const ( - FraudCheckStatusWAITING FraudCheckStatus = "WAITING" - FraudCheckStatusNOT_FRAUD FraudCheckStatus = "NOT_FRAUD" - FraudCheckStatusFRAUD FraudCheckStatus = "FRAUD" + FraudCheckStatus_WAITING FraudCheckStatus = "WAITING" + FraudCheckStatus_NOT_FRAUD FraudCheckStatus = "NOT_FRAUD" + FraudCheckStatus_FRAUD FraudCheckStatus = "FRAUD" ) // apm additional action type declaration const ( - REDIRECT_TO_URL ApmAdditionalAction = "REDIRECT_TO_URL" - OTP_REQUIRED ApmAdditionalAction = "OTP_REQUIRED" - NONE ApmAdditionalAction = "NONE" + ApmAdditionalAction_REDIRECT_TO_URL ApmAdditionalAction = "REDIRECT_TO_URL" + ApmAdditionalAction_OTP_REQUIRED ApmAdditionalAction = "OTP_REQUIRED" + ApmAdditionalAction_NONE ApmAdditionalAction = "NONE" ) // report file type declaration const ( - CSV ReportFileType = "CSV" - XLSX ReportFileType = "XLSX" + ReportFileType_CSV ReportFileType = "CSV" + ReportFileType_XLSX ReportFileType = "XLSX" ) // wallet transaction type declaration const ( - PAYMENT_REDEEM WalletTransactionType = "PAYMENT_REDEEM" - REFUND_DEPOSIT WalletTransactionType = "REFUND_DEPOSIT" - REFUND_TX_DEPOSIT WalletTransactionType = "REFUND_TX_DEPOSIT" - WITHDRAW WalletTransactionType = "WITHDRAW" - CANCEL_REFUND_WALLET_TO_CARD WalletTransactionType = "CANCEL_REFUND_WALLET_TO_CARD" - REFUND_WALLET_TX_TO_CARD WalletTransactionType = "REFUND_WALLET_TX_TO_CARD" - REFUND_WALLET_TX_FUND_TRANSFER WalletTransactionType = "REFUND_WALLET_TX_FUND_TRANSFER" - CANCEL_REFUND_TO_WALLET WalletTransactionType = "CANCEL_REFUND_TO_WALLET" - REFUND_TX_TO_WALLET WalletTransactionType = "REFUND_TX_TO_WALLET" - MANUAL_REFUND_TX_TO_WALLET WalletTransactionType = "MANUAL_REFUND_TX_TO_WALLET" - SETTLEMENT_EARNINGS WalletTransactionType = "SETTLEMENT_EARNINGS" - DEPOSIT_FROM_CARD WalletTransactionType = "DEPOSIT_FROM_CARD" - DEPOSIT_FROM_APM WalletTransactionType = "DEPOSIT_FROM_APM" - DEPOSIT_FROM_FUND_TRANSFER WalletTransactionType = "DEPOSIT_FROM_FUND_TRANSFER" - REMITTANCE WalletTransactionType = "REMITTANCE" - LOYALTY WalletTransactionType = "LOYALTY" - WITHDRAW_CANCEL WalletTransactionType = "WITHDRAW_CANCEL" - MERCHANT_BALANCE_RESET WalletTransactionType = "MERCHANT_BALANCE_RESET" + WalletTransactionType_PAYMENT_REDEEM WalletTransactionType = "PAYMENT_REDEEM" + WalletTransactionType_REFUND_DEPOSIT WalletTransactionType = "REFUND_DEPOSIT" + WalletTransactionType_REFUND_TX_DEPOSIT WalletTransactionType = "REFUND_TX_DEPOSIT" + WalletTransactionType_WITHDRAW WalletTransactionType = "WITHDRAW" + WalletTransactionType_CANCEL_REFUND_WALLET_TO_CARD WalletTransactionType = "CANCEL_REFUND_WALLET_TO_CARD" + WalletTransactionType_REFUND_WALLET_TX_TO_CARD WalletTransactionType = "REFUND_WALLET_TX_TO_CARD" + WalletTransactionType_REFUND_WALLET_TX_FUND_TRANSFER WalletTransactionType = "REFUND_WALLET_TX_FUND_TRANSFER" + WalletTransactionType_CANCEL_REFUND_TO_WALLET WalletTransactionType = "CANCEL_REFUND_TO_WALLET" + WalletTransactionType_REFUND_TX_TO_WALLET WalletTransactionType = "REFUND_TX_TO_WALLET" + WalletTransactionType_MANUAL_REFUND_TX_TO_WALLET WalletTransactionType = "MANUAL_REFUND_TX_TO_WALLET" + WalletTransactionType_SETTLEMENT_EARNINGS WalletTransactionType = "SETTLEMENT_EARNINGS" + WalletTransactionType_DEPOSIT_FROM_CARD WalletTransactionType = "DEPOSIT_FROM_CARD" + WalletTransactionType_DEPOSIT_FROM_APM WalletTransactionType = "DEPOSIT_FROM_APM" + WalletTransactionType_DEPOSIT_FROM_FUND_TRANSFER WalletTransactionType = "DEPOSIT_FROM_FUND_TRANSFER" + WalletTransactionType_REMITTANCE WalletTransactionType = "REMITTANCE" + WalletTransactionType_LOYALTY WalletTransactionType = "LOYALTY" + WalletTransactionType_WITHDRAW_CANCEL WalletTransactionType = "WITHDRAW_CANCEL" + WalletTransactionType_MERCHANT_BALANCE_RESET WalletTransactionType = "MERCHANT_BALANCE_RESET" +) + +const ( + WebhookEventType_API_AUTH WebhookEventType = "API_AUTH" + WebhookEventType_API_VERIFY_AND_AUTH WebhookEventType = "API_VERIFY_AND_AUTH" + WebhookEventType_CHECKOUTFORM_AUTH WebhookEventType = "CHECKOUTFORM_AUTH" + WebhookEventType_THREEDS_VERIFY WebhookEventType = "THREEDS_VERIFY" +) + +const ( + WebhookStatus_SUCCESS WebhookStatus = "SUCCESS" + WebhookStatus_FAILURE WebhookStatus = "FAILURE" +) + +const ( + PosStatus_DELETED PosStatus = "DELETED" + PosStatus_PASSIVE PosStatus = "PASSIVE" + PosStatus_ACTIVE PosStatus = "ACTIVE" + PosStatus_REFUND_ONLY PosStatus = "REFUND_ONLY" + PosStatus_AUTOPILOT PosStatus = "AUTOPILOT" +) + +const ( + PosIntegrator_YKB PosIntegrator = "YKB" + PosIntegrator_GARANTI PosIntegrator = "GARANTI" + PosIntegrator_ISBANK PosIntegrator = "ISBANK" + PosIntegrator_AKBANK PosIntegrator = "AKBANK" + PosIntegrator_ZIRAATBANK PosIntegrator = "ZIRAATBANK" + PosIntegrator_ZIRAATBANK_INNOVA PosIntegrator = "ZIRAATBANK_INNOVA" + PosIntegrator_KUVEYTTURK PosIntegrator = "KUVEYTTURK" + PosIntegrator_HALKBANK PosIntegrator = "HALKBANK" + PosIntegrator_DENIZBANK PosIntegrator = "DENIZBANK" + PosIntegrator_VAKIFBANK PosIntegrator = "VAKIFBANK" + PosIntegrator_FINANSBANK PosIntegrator = "FINANSBANK" + PosIntegrator_FINANSBANK_ASSECO PosIntegrator = "FINANSBANK_ASSECO" + PosIntegrator_FIBABANK PosIntegrator = "FIBABANK" + PosIntegrator_FIBABANK_ASSECO PosIntegrator = "FIBABANK_ASSECO" + PosIntegrator_ANADOLUBANK PosIntegrator = "ANADOLUBANK" + PosIntegrator_PARAM_POS PosIntegrator = "PARAM_POS" + PosIntegrator_IYZICO PosIntegrator = "IYZICO" + PosIntegrator_SIPAY PosIntegrator = "SIPAY" + PosIntegrator_PAYNET PosIntegrator = "PAYNET" + PosIntegrator_PAYTR PosIntegrator = "PAYTR" + PosIntegrator_BIRLESIK_ODEME PosIntegrator = "BIRLESIK_ODEME" + PosIntegrator_MOKA PosIntegrator = "MOKA" + PosIntegrator_STRIPE PosIntegrator = "STRIPE" + PosIntegrator_TEB PosIntegrator = "TEB" + PosIntegrator_IPARA PosIntegrator = "IPARA" + PosIntegrator_OZAN PosIntegrator = "OZAN" + PosIntegrator_BRAINTREE PosIntegrator = "BRAINTREE" + PosIntegrator_NKOLAY PosIntegrator = "NKOLAY" + PosIntegrator_FAKE PosIntegrator = "FAKE" ) const ( - API_AUTH WebhookEventType = "API_AUTH" - API_VERIFY_AND_AUTH WebhookEventType = "API_VERIFY_AND_AUTH" - CHECKOUTFORM_AUTH WebhookEventType = "CHECKOUTFORM_AUTH" - THREEDS_VERIFY WebhookEventType = "THREEDS_VERIFY" + PosUserType_API PosUserType = "API" ) const ( - WebhookStatusSUCCESS WebhookStatus = "SUCCESS" - WebhookStatusFAILURE WebhookStatus = "FAILURE" + PosOperationType_STANDARD PosOperationType = "STANDARD" + PosOperationType_PROVAUT PosOperationType = "PROVAUT" + PosOperationType_PROVRFN PosOperationType = "PROVRFN" + PosOperationType_PAYMENT PosOperationType = "PAYMENT" + PosOperationType_REFUND PosOperationType = "REFUND" + PosOperationType_INQUIRY PosOperationType = "INQUIRY" ) const ( - FileStatusCREATED FileStatus = "CREATED" - FileStatusUPLOADED FileStatus = "UPLOADED" - FileStatusAPPROVED FileStatus = "APPROVED" + FileStatus_CREATED FileStatus = "CREATED" + FileStatus_UPLOADED FileStatus = "UPLOADED" + FileStatus_APPROVED FileStatus = "APPROVED" ) const ( - AccountOwnerMERCHANT AccountOwner = "MERCHANT" - AccountOwnerSUB_MERCHANT_MEMBER AccountOwner = "SUB_MERCHANT_MEMBER" + AdditionalAction_CONTINUE_IN_CLIENT AdditionalAction = "CONTINUE_IN_CLIENT" + AdditionalAction_SHOW_HTML_CONTENT AdditionalAction = "SHOW_HTML_CONTENT" + AdditionalAction_REDIRECT_TO_URL AdditionalAction = "REDIRECT_TO_URL" + AdditionalAction_NONE AdditionalAction = "NONE" ) const ( - PayoutAccountTypeWISE PayoutAccountType = "WISE" + AccountOwner_MERCHANT AccountOwner = "MERCHANT" + AccountOwner_SUB_MERCHANT_MEMBER AccountOwner = "SUB_MERCHANT_MEMBER" +) + +const ( + PayoutAccountType_WISE PayoutAccountType = "WISE" ) // requests @@ -410,6 +496,10 @@ type Init3DSPaymentRequest struct { Retry bool `json:"retry"` } +type Complete3DSPaymentRequest struct { + PaymentId int64 `json:"paymentId"` +} + type InitCheckoutPaymentRequest struct { Price float64 `json:"price,omitempty"` PaidPrice float64 `json:"paidPrice,omitempty"` @@ -462,8 +552,31 @@ type CompleteApmPaymentRequest struct { AdditionalParams map[string]string `json:"additionalParams,omitempty"` } -type Complete3DSPaymentRequest struct { - PaymentId int64 `json:"paymentId"` +type InitPosApmPaymentRequest struct { + Price float64 `json:"price,omitempty"` + PaidPrice float64 `json:"paidPrice,omitempty"` + PosAlias string `json:"posAlias,omitempty"` + Currency Currency `json:"currency,omitempty"` + ConversationId string `json:"conversationId,omitempty"` + ExternalId string `json:"externalId,omitempty"` + CallbackUrl string `json:"callbackUrl,omitempty"` + PaymentPhase PaymentPhase `json:"paymentPhase,omitempty"` + PaymentGroup PaymentGroup `json:"paymentGroup,omitempty"` + PaymentChannel string `json:"paymentChannel,omitempty"` + BuyerMemberId int64 `json:"buyerMemberId,omitempty"` + BankOrderId string `json:"bankOrderId,omitempty"` + ClientIp string `json:"clientIp,omitempty"` + Items []PaymentItem `json:"items"` + AdditionalParams map[string]string `json:"additionalParams"` + Installments []PosApmInstallment `json:"installments"` + PaymentProvider PosApmPaymentProvider `json:"paymentProvider,omitempty"` + FraudParams *FraudCheckParameters `json:"fraudParams,omitempty"` + CheckoutFormToken string `json:"checkoutFormToken,omitempty"` +} + +type CompletePosApmPaymentRequest struct { + PaymentId int64 `json:"paymentId"` + AdditionalParams map[string]interface{} `json:"additionalParams"` } type PostAuthPaymentRequest struct { @@ -729,6 +842,22 @@ type CompleteApmPaymentResponse struct { PaymentError *PaymentError `json:"paymentError"` } +type InitPosApmPaymentResponse struct { + PaymentId *int64 `json:"paymentId"` + HtmlContent *string `json:"htmlContent"` + PaymentStatus *PaymentStatus `json:"paymentStatus"` + AdditionalAction *AdditionalAction `json:"additionalAction"` + AdditionalData map[string]any `json:"additionalData"` + PaymentError *PaymentError `json:"paymentError"` +} + +type CompletePosApmPaymentResponse struct { + PaymentId *int64 `json:"paymentId"` + ConversationId *string `json:"conversationId"` + PaymentStatus *PaymentStatus `json:"paymentStatus"` + PaymentError *PaymentError `json:"paymentError"` +} + type DepositPaymentResponse struct { Id *int64 `json:"id"` CreatedDate *TimeResponse `json:"createdDate"` @@ -1574,6 +1703,11 @@ type FraudCheckParameters struct { BuyerEmail string `json:"buyerEmail,omitempty"` } +type PosApmInstallment struct { + Number *int `json:"number,omitempty"` + TotalPrice *float64 `json:"totalPrice,omitempty"` +} + type PaymentItem struct { Name string `json:"name,omitempty"` Price float64 `json:"price,omitempty"` diff --git a/adapter/payment.go b/adapter/payment.go index 7c974ea..0053931 100644 --- a/adapter/payment.go +++ b/adapter/payment.go @@ -210,6 +210,40 @@ func (api *Payment) CompleteApmPayment(ctx context.Context, request CompleteApmP return response.Data, nil } +func (api *Payment) InitPosApmPayment(ctx context.Context, request InitPosApmPaymentRequest) (*InitPosApmPaymentResponse, error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/pos-apm-payments/init", request) + + if err != nil { + return nil, err + } + + response := &Response[InitPosApmPaymentResponse]{} + err = api.Client.Do(ctx, newRequest, response) + + if err != nil { + return nil, err + } + + return response.Data, nil +} + +func (api *Payment) CompletePosApmPayment(ctx context.Context, request CompletePosApmPaymentRequest) (*CompletePosApmPaymentResponse, error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/pos-apm-payments/complete", request) + + if err != nil { + return nil, err + } + + response := &Response[CompletePosApmPaymentResponse]{} + err = api.Client.Do(ctx, newRequest, response) + + if err != nil { + return nil, err + } + + return response.Data, nil +} + func (api *Payment) Init3DSDepositPayment(ctx context.Context, request DepositPaymentRequest) (*Init3DSPaymentResponse, error) { newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/deposits/3ds-init", request) diff --git a/go.mod b/go.mod index a46e93a..755d04f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/craftgate/craftgate-go-client -go 1.19 +go 1.21 require ( github.com/davecgh/go-spew v1.1.1 diff --git a/tests/file_reporting_test.go b/tests/file_reporting_test.go index 5b4c084..d379169 100644 --- a/tests/file_reporting_test.go +++ b/tests/file_reporting_test.go @@ -1,26 +1,26 @@ 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" - "testing" - "time" + "context" + "github.com/craftgate/craftgate-go-client/adapter" + craftgate "github.com/craftgate/craftgate-go-client/adapter" + "github.com/davecgh/go-spew/spew" + "testing" + "time" ) var fileReportingClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io") func TestFileReporting_RetrieveDailyTransactionReport(t *testing.T) { - request := adapter.RetrieveDailyTransactionReportRequest{ - ReportDate: craftgate.DateOf(time.Date(2022, 11, 11, 0, 0, 0, 0, time.UTC)), - FileType: craftgate.CSV, - } + request := adapter.RetrieveDailyTransactionReportRequest{ + ReportDate: craftgate.DateOf(time.Date(2022, 11, 11, 0, 0, 0, 0, time.UTC)), + FileType: craftgate.ReportFileType_CSV, + } - res, err := fileReportingClient.FileReporting.RetrieveDailyTransactionReport(context.Background(), request) - _, _ = spew.Printf("%#v\n", res) + res, err := fileReportingClient.FileReporting.RetrieveDailyTransactionReport(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } diff --git a/tests/fraud_test.go b/tests/fraud_test.go index 7145138..86e6b25 100644 --- a/tests/fraud_test.go +++ b/tests/fraud_test.go @@ -1,78 +1,78 @@ 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" - "testing" + "context" + "github.com/craftgate/craftgate-go-client/adapter" + craftgate "github.com/craftgate/craftgate-go-client/adapter" + "github.com/davecgh/go-spew/spew" + "testing" ) var fraudClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io") func Test_SearchFraudChecks(t *testing.T) { - request := adapter.SearchFraudChecksRequest{ - Page: 0, Size: 10, - } + request := adapter.SearchFraudChecksRequest{ + Page: 0, Size: 10, + } - res, err := fraudClient.Fraud.SearchFraudChecks(context.Background(), request) - _, _ = spew.Printf("%#v\n", res) + res, err := fraudClient.Fraud.SearchFraudChecks(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } func Test_RetrieveAllFraudValueList(t *testing.T) { - res, err := fraudClient.Fraud.RetrieveAllFraudValueList(context.Background()) - _, _ = spew.Printf("%#v\n", res) + res, err := fraudClient.Fraud.RetrieveAllFraudValueList(context.Background()) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } func Test_RetrieveFraudValueList(t *testing.T) { - res, err := fraudClient.Fraud.RetrieveFraudValueList(context.Background(), "blockedBuyerIdList") - _, _ = spew.Printf("%#v\n", res) + res, err := fraudClient.Fraud.RetrieveFraudValueList(context.Background(), "blockedBuyerIdList") + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } func Test_CreateFraudValueList(t *testing.T) { - err := fraudClient.Fraud.CreateFraudValueList(context.Background(), "myTestList") + err := fraudClient.Fraud.CreateFraudValueList(context.Background(), "myTestList") - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } func Test_DeleteFraudValueList(t *testing.T) { - err := fraudClient.Fraud.DeleteFraudValueList(context.Background(), "myTestList") + err := fraudClient.Fraud.DeleteFraudValueList(context.Background(), "myTestList") - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } func Test_AddValueToFraudValueList(t *testing.T) { - request := adapter.FraudValueListRequest{ - ListName: "ipList", - Value: "999.999.999.999", - } - err := fraudClient.Fraud.AddValueToFraudValueList(context.Background(), request) - - if err != nil { - t.Errorf("Error %s", err) - } + request := adapter.FraudValueListRequest{ + ListName: "ipList", + Value: "999.999.999.999", + } + err := fraudClient.Fraud.AddValueToFraudValueList(context.Background(), request) + + if err != nil { + t.Errorf("Error %s", err) + } } func Test_RemoveValueFromFraudValueList(t *testing.T) { - err := fraudClient.Fraud.RemoveValueFromFraudValueList(context.Background(), "ipList", "999.999.999.999") + err := fraudClient.Fraud.RemoveValueFromFraudValueList(context.Background(), "ipList", "999.999.999.999") - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } diff --git a/tests/hook_test.go b/tests/hook_test.go index 13f7f64..f36ddea 100644 --- a/tests/hook_test.go +++ b/tests/hook_test.go @@ -12,9 +12,9 @@ func TestHook_VerifyWebhook(t *testing.T) { merchantHookKey := "Aoh7tReTybO6wOjBmOJFFsOR53SBojEp" incomingSignature := "0wRB5XqWJxwwPbn5Z9TcbHh8EGYFufSYTsRMB74N094=" webhookData := craftgate.WebhookData{ - EventType: craftgate.API_VERIFY_AND_AUTH, + EventType: craftgate.WebhookEventType_API_VERIFY_AND_AUTH, EventTimestamp: 1661521221, - Status: craftgate.WebhookStatusSUCCESS, + Status: craftgate.WebhookStatus_SUCCESS, PayloadId: "584", } @@ -27,9 +27,9 @@ func TestHook_NotVerifyWebhook(t *testing.T) { merchantHookKey := "Aoh7tReTybO6wOjBmOJFFsOR53SBojEp" incomingSignature := "Bsa498wcnaasd4bhx8anxıxcsdnxanalkdjcahxhd" webhookData := craftgate.WebhookData{ - EventType: craftgate.API_VERIFY_AND_AUTH, + EventType: craftgate.WebhookEventType_API_VERIFY_AND_AUTH, EventTimestamp: 1661521221, - Status: craftgate.WebhookStatusSUCCESS, + Status: craftgate.WebhookStatus_SUCCESS, PayloadId: "584", } diff --git a/tests/installment_test.go b/tests/installment_test.go index 22f8d44..5d8f168 100644 --- a/tests/installment_test.go +++ b/tests/installment_test.go @@ -23,7 +23,7 @@ func Test_SearchInstallments(t *testing.T) { request := adapter.SearchInstallmentsRequest{ BinNumber: "487074", Price: 100, - Currency: craftgate.TRY, + Currency: craftgate.Currency_TRY, } res, err := installmentClient.Installment.SearchInstallments(context.Background(), request) diff --git a/tests/masterpass_test.go b/tests/masterpass_test.go index 58c1c34..ac9db9e 100644 --- a/tests/masterpass_test.go +++ b/tests/masterpass_test.go @@ -1,103 +1,103 @@ 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" + "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 masterpassClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io") func TestMasterpass_CheckMasterpassUser(t *testing.T) { - request := adapter.CheckMasterpassUserRequest{ - MasterpassGsmNumber: "903000000000", - } - res, err := masterpassClient.Masterpass.CheckMasterpassUser(context.Background(), request) - _, _ = spew.Printf("%#v\n", res) - - if err != nil { - t.Errorf("Error %s", err) - } + request := adapter.CheckMasterpassUserRequest{ + MasterpassGsmNumber: "903000000000", + } + res, err := masterpassClient.Masterpass.CheckMasterpassUser(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } } func TestMasterpass_GenerateMasterpassPaymentToken(t *testing.T) { - request := adapter.MasterpassPaymentTokenGenerateRequest{ - UserId: "masterpass-user-id", - Msisdn: "900000000000", - BinNumber: "404308", - ForceThreeDS: true, - CreatePayment: craftgate.MasterpassCreatePayment{ - Price: 1.25, - PaidPrice: 1.25, - Installment: 1, - Currency: craftgate.TRY, - PaymentGroup: craftgate.LISTING_OR_SUBSCRIPTION, - ConversationId: "foo-bar", - ExternalId: "115", - Items: []craftgate.PaymentItem{ - { - Name: "Item 1", - Price: 1, - ExternalId: "1", - }, - { - Name: "Item 2", - Price: 0.25, - ExternalId: "2", - }, - }, - }, - } - - res, err := masterpassClient.Masterpass.GenerateMasterpassPaymentToken(context.Background(), request) - - require.NotNil(t, res.Token) - require.NotNil(t, res.ReferenceId) - if err != nil { - t.Errorf("Error %s", err) - } + request := adapter.MasterpassPaymentTokenGenerateRequest{ + UserId: "masterpass-user-id", + Msisdn: "900000000000", + BinNumber: "404308", + ForceThreeDS: true, + CreatePayment: craftgate.MasterpassCreatePayment{ + Price: 1.25, + PaidPrice: 1.25, + Installment: 1, + Currency: craftgate.Currency_TRY, + PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION, + ConversationId: "foo-bar", + ExternalId: "115", + Items: []craftgate.PaymentItem{ + { + Name: "Item 1", + Price: 1, + ExternalId: "1", + }, + { + Name: "Item 2", + Price: 0.25, + ExternalId: "2", + }, + }, + }, + } + + res, err := masterpassClient.Masterpass.GenerateMasterpassPaymentToken(context.Background(), request) + + require.NotNil(t, res.Token) + require.NotNil(t, res.ReferenceId) + if err != nil { + t.Errorf("Error %s", err) + } } func TestMasterpass_CompleteMasterpassPayment(t *testing.T) { - request := adapter.MasterpassPaymentCompleteRequest{ - ReferenceId: "referenceId", - Token: "token", - } + request := adapter.MasterpassPaymentCompleteRequest{ + ReferenceId: "referenceId", + Token: "token", + } - res, err := masterpassClient.Masterpass.CompleteMasterpassPayment(context.Background(), request) + res, err := masterpassClient.Masterpass.CompleteMasterpassPayment(context.Background(), request) - require.NotNil(t, res.Id) - if err != nil { - t.Errorf("Error %s", err) - } + require.NotNil(t, res.Id) + if err != nil { + t.Errorf("Error %s", err) + } } func TestMasterpass_Init3DSMasterpassPayment(t *testing.T) { - request := adapter.MasterpassPaymentThreeDSInitRequest{ - ReferenceId: "referenceId", - CallbackUrl: "https://www.your-website.com/craftgate-3DSecure-callback", - } + request := adapter.MasterpassPaymentThreeDSInitRequest{ + ReferenceId: "referenceId", + CallbackUrl: "https://www.your-website.com/craftgate-3DSecure-callback", + } - res, err := masterpassClient.Masterpass.Init3DSMasterpassPayment(context.Background(), request) + res, err := masterpassClient.Masterpass.Init3DSMasterpassPayment(context.Background(), request) - require.NotNil(t, res.ReturnUrl) - if err != nil { - t.Errorf("Error %s", err) - } + require.NotNil(t, res.ReturnUrl) + if err != nil { + t.Errorf("Error %s", err) + } } func TestMasterpass_Complete3DSMasterpassPayment(t *testing.T) { - request := adapter.MasterpassPaymentThreeDSCompleteRequest{ - PaymentId: 1, - } + request := adapter.MasterpassPaymentThreeDSCompleteRequest{ + PaymentId: 1, + } - res, err := masterpassClient.Masterpass.Complete3DSMasterpassPayment(context.Background(), request) + res, err := masterpassClient.Masterpass.Complete3DSMasterpassPayment(context.Background(), request) - require.NotNil(t, res.Id) - if err != nil { - t.Errorf("Error %s", err) - } + require.NotNil(t, res.Id) + if err != nil { + t.Errorf("Error %s", err) + } } diff --git a/tests/onboarding_test.go b/tests/onboarding_test.go index 8f54f23..f684648 100644 --- a/tests/onboarding_test.go +++ b/tests/onboarding_test.go @@ -44,7 +44,7 @@ func Test_CreateSubMerchantMember(t *testing.T) { IdentityNumber: "11111111110", LegalCompanyTitle: "Dem Zeytinyağı Üretim Ltd. Şti.", Name: "Dem Zeytinyağı Üretim Ltd. Şti.", - MemberType: craftgate.LIMITED_OR_JOINT_STOCK_COMPANY, + MemberType: craftgate.MemberType_LIMITED_OR_JOINT_STOCK_COMPANY, TaxNumber: "1111111114", TaxOffice: "Erenköy", Address: "Suadiye Mah. Örnek Cd. No:23, 34740 Kadıköy/İstanbul", @@ -71,7 +71,7 @@ func Test_CreateBuyerAndSubMerchantMember(t *testing.T) { IdentityNumber: "11111111110", LegalCompanyTitle: "Dem Zeytinyağı Üretim Ltd. Şti.", Name: "Dem Zeytinyağı Üretim Ltd. Şti.", - MemberType: craftgate.LIMITED_OR_JOINT_STOCK_COMPANY, + MemberType: craftgate.MemberType_LIMITED_OR_JOINT_STOCK_COMPANY, TaxNumber: "1111111114", TaxOffice: "Erenköy", Address: "Suadiye Mah. Örnek Cd. No:23, 34740 Kadıköy/İstanbul", @@ -97,8 +97,8 @@ func Test_UpdateSubMerchantMember(t *testing.T) { IdentityNumber: "11111111110", LegalCompanyTitle: "Dem Zeytinyağı Üretim Ltd. Şti.", Name: "Dem Zeytinyağı Üretim Ltd. Şti.", - MemberType: craftgate.LIMITED_OR_JOINT_STOCK_COMPANY, - SettlementEarningsDestination: craftgate.SettlementEarningsDestinationWALLET, + MemberType: craftgate.MemberType_LIMITED_OR_JOINT_STOCK_COMPANY, + SettlementEarningsDestination: craftgate.SettlementEarningsDestination_WALLET, TaxNumber: "1111111114", TaxOffice: "Erenköy", Address: "Suadiye Mah. Örnek Cd. No:23, 34740 Kadıköy/İstanbul", @@ -124,7 +124,7 @@ func Test_UpdateBuyerMember(t *testing.T) { IdentityNumber: "11111111110", LegalCompanyTitle: "Dem Zeytinyağı Üretim Ltd. Şti.", Name: "Dem Zeytinyağı Üretim Ltd. Şti.", - MemberType: craftgate.PERSONAL, + MemberType: craftgate.MemberType_PERSONAL, TaxNumber: "1111111114", TaxOffice: "Erenköy", Address: "Suadiye Mah. Örnek Cd. No:23, 34740 Kadıköy/İstanbul", diff --git a/tests/pay_by_link_test.go b/tests/pay_by_link_test.go index bc3f681..7b84d89 100644 --- a/tests/pay_by_link_test.go +++ b/tests/pay_by_link_test.go @@ -1,78 +1,78 @@ 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" - "testing" + "context" + "github.com/craftgate/craftgate-go-client/adapter" + craftgate "github.com/craftgate/craftgate-go-client/adapter" + "github.com/davecgh/go-spew/spew" + "testing" ) var payByLinkClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io") func Test_CreateProduct(t *testing.T) { - request := adapter.CreateProductRequest{ - Name: "A new Product", - Channel: "API", - Price: 10, - Currency: craftgate.TRY, - EnabledInstallments: []int{1, 2, 3, 6}, - } + request := adapter.CreateProductRequest{ + Name: "A new Product", + Channel: "API", + Price: 10, + Currency: craftgate.Currency_TRY, + EnabledInstallments: []int{1, 2, 3, 6}, + } - res, err := payByLinkClient.PayByLink.CreateProduct(context.Background(), request) - _, _ = spew.Printf("%#v\n", res) + res, err := payByLinkClient.PayByLink.CreateProduct(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } func Test_UpdateProduct(t *testing.T) { - request := adapter.UpdateProductRequest{ - Name: "A new Product", - Status: craftgate.ACTIVE, - Channel: "API", - Price: 10, - Currency: craftgate.TRY, - EnabledInstallments: []int{1, 2, 3, 6, 9}, - } + request := adapter.UpdateProductRequest{ + Name: "A new Product", + Status: craftgate.Status_ACTIVE, + Channel: "API", + Price: 10, + Currency: craftgate.Currency_TRY, + EnabledInstallments: []int{1, 2, 3, 6, 9}, + } - res, err := payByLinkClient.PayByLink.UpdateProduct(context.Background(), 1, request) - _, _ = spew.Printf("%#v\n", res) + res, err := payByLinkClient.PayByLink.UpdateProduct(context.Background(), 1, request) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } func Test_RetrieveProduct(t *testing.T) { - res, err := payByLinkClient.PayByLink.RetrieveProduct(context.Background(), 1) - _, _ = spew.Printf("%#v\n", res) + res, err := payByLinkClient.PayByLink.RetrieveProduct(context.Background(), 1) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } func Test_DeleteProduct(t *testing.T) { - err := payByLinkClient.PayByLink.DeleteProduct(context.Background(), 1) + err := payByLinkClient.PayByLink.DeleteProduct(context.Background(), 1) - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } func Test_SearchProducts(t *testing.T) { - request := adapter.SearchProductsRequest{ - Page: 0, - Size: 10, - Currency: craftgate.TRY, - } + request := adapter.SearchProductsRequest{ + Page: 0, + Size: 10, + Currency: craftgate.Currency_TRY, + } - res, err := payByLinkClient.PayByLink.SearchProducts(context.Background(), request) - _, _ = spew.Printf("%#v\n", res) + res, err := payByLinkClient.PayByLink.SearchProducts(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } diff --git a/tests/payment_reporting_test.go b/tests/payment_reporting_test.go index f7c7a51..c23e1d8 100644 --- a/tests/payment_reporting_test.go +++ b/tests/payment_reporting_test.go @@ -1,95 +1,95 @@ 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" - "testing" - "time" + "context" + "github.com/craftgate/craftgate-go-client/adapter" + craftgate "github.com/craftgate/craftgate-go-client/adapter" + "github.com/davecgh/go-spew/spew" + "testing" + "time" ) var paymentReportingClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io") func Test_SearchPayment(t *testing.T) { - request := adapter.SearchPaymentsRequest{ - Page: 0, Size: 10, - PaymentType: craftgate.CARD_PAYMENT, - PaymentStatus: craftgate.SUCCESS, - Currency: craftgate.TRY, - MinCreatedDate: time.Now().AddDate(0, 0, -180), - MaxCreatedDate: time.Now(), - } - res, err := paymentReportingClient.PaymentReporting.SearchPayments(context.Background(), request) - _, _ = spew.Printf("%#v\n", res) - - if err != nil { - t.Errorf("Error %s", err) - } + request := adapter.SearchPaymentsRequest{ + Page: 0, Size: 10, + PaymentType: craftgate.PaymentType_CARD_PAYMENT, + PaymentStatus: craftgate.PaymentStatus_SUCCESS, + Currency: craftgate.Currency_TRY, + MinCreatedDate: time.Now().AddDate(0, 0, -180), + MaxCreatedDate: time.Now(), + } + res, err := paymentReportingClient.PaymentReporting.SearchPayments(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } } func Test_SearchPaymentRefunds(t *testing.T) { - request := adapter.SearchPaymentRefundsRequest{ - Page: 0, Size: 10, - Currency: craftgate.TRY, - MinCreatedDate: time.Now().AddDate(0, 0, -180), - MaxCreatedDate: time.Now(), - } - res, err := paymentReportingClient.PaymentReporting.SearchPaymentRefunds(context.Background(), request) - _, _ = spew.Printf("%#v\n", res) - - if err != nil { - t.Errorf("Error %s", err) - } + request := adapter.SearchPaymentRefundsRequest{ + Page: 0, Size: 10, + Currency: craftgate.Currency_TRY, + MinCreatedDate: time.Now().AddDate(0, 0, -180), + MaxCreatedDate: time.Now(), + } + res, err := paymentReportingClient.PaymentReporting.SearchPaymentRefunds(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } } func Test_SearchPaymentTransactionRefunds(t *testing.T) { - request := adapter.SearchPaymentTransactionRefundsRequest{ - Page: 0, Size: 10, - Currency: craftgate.TRY, - MinCreatedDate: time.Now().AddDate(0, 0, -180), - MaxCreatedDate: time.Now(), - } - res, err := paymentReportingClient.PaymentReporting.SearchPaymentTransactionRefunds(context.Background(), request) - _, _ = spew.Printf("%#v\n", res) - - if err != nil { - t.Errorf("Error %s", err) - } + request := adapter.SearchPaymentTransactionRefundsRequest{ + Page: 0, Size: 10, + Currency: craftgate.Currency_TRY, + MinCreatedDate: time.Now().AddDate(0, 0, -180), + MaxCreatedDate: time.Now(), + } + res, err := paymentReportingClient.PaymentReporting.SearchPaymentTransactionRefunds(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } } func Test_RetrievePayment(t *testing.T) { - res, err := paymentReportingClient.PaymentReporting.RetrievePayment(context.Background(), 123) - _, _ = spew.Printf("%#v\n", res) + res, err := paymentReportingClient.PaymentReporting.RetrievePayment(context.Background(), 123) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } func Test_RetrievePaymentTransactions(t *testing.T) { - res, err := paymentReportingClient.PaymentReporting.RetrievePaymentTransactions(context.Background(), 123) - _, _ = spew.Printf("%#v\n", res) + res, err := paymentReportingClient.PaymentReporting.RetrievePaymentTransactions(context.Background(), 123) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } func Test_RetrievePaymentRefunds(t *testing.T) { - res, err := paymentReportingClient.PaymentReporting.RetrievePaymentRefunds(context.Background(), 123) - _, _ = spew.Printf("%#v\n", res) + res, err := paymentReportingClient.PaymentReporting.RetrievePaymentRefunds(context.Background(), 123) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } func Test_RetrievePaymentTransactionRefunds(t *testing.T) { - res, err := paymentReportingClient.PaymentReporting.RetrievePaymentTransactionRefunds(context.Background(), 123, 789) - _, _ = spew.Printf("%#v\n", res) + res, err := paymentReportingClient.PaymentReporting.RetrievePaymentTransactionRefunds(context.Background(), 123, 789) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } diff --git a/tests/payment_test.go b/tests/payment_test.go index 05c4225..c0ade50 100644 --- a/tests/payment_test.go +++ b/tests/payment_test.go @@ -16,8 +16,8 @@ func TestPayment_CreatePayment(t *testing.T) { Price: 1.25, PaidPrice: 1.25, Installment: 1, - Currency: craftgate.TRY, - PaymentGroup: craftgate.LISTING_OR_SUBSCRIPTION, + Currency: craftgate.Currency_TRY, + PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION, ConversationId: "foo-bar", ExternalId: "115", Card: &craftgate.Card{ @@ -51,11 +51,11 @@ func TestPayment_CreatePayment(t *testing.T) { func TestPayment_CreateApmPayment(t *testing.T) { request := adapter.CreateApmPaymentRequest{ - ApmType: craftgate.ApmTypeCASH_ON_DELIVERY, + ApmType: craftgate.ApmType_CASH_ON_DELIVERY, Price: 1.25, PaidPrice: 1.25, - Currency: craftgate.TRY, - PaymentGroup: craftgate.LISTING_OR_SUBSCRIPTION, + Currency: craftgate.Currency_TRY, + PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION, ConversationId: "foo-bar", ExternalId: "115", Items: []craftgate.PaymentItem{ @@ -95,8 +95,8 @@ func TestPayment_Init3DSPayment(t *testing.T) { Price: 1.25, PaidPrice: 1.25, Installment: 1, - Currency: craftgate.TRY, - PaymentGroup: craftgate.LISTING_OR_SUBSCRIPTION, + Currency: craftgate.Currency_TRY, + PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION, ConversationId: "foo-bar", ExternalId: "115", Card: &craftgate.Card{ @@ -147,9 +147,9 @@ func TestPayment_CreatePreAuthPayment(t *testing.T) { Price: 1.25, PaidPrice: 1.25, Installment: 1, - Currency: craftgate.TRY, - PaymentGroup: craftgate.LISTING_OR_SUBSCRIPTION, - PaymentPhase: craftgate.PRE_AUTH, + Currency: craftgate.Currency_TRY, + PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION, + PaymentPhase: craftgate.PaymentPhase_PRE_AUTH, ConversationId: "foo-bar", ExternalId: "115", Card: &craftgate.Card{ @@ -197,9 +197,9 @@ func TestPayment_InitCheckoutPayment(t *testing.T) { request := adapter.InitCheckoutPaymentRequest{ Price: 1.25, PaidPrice: 1.25, - Currency: craftgate.TRY, - PaymentGroup: craftgate.LISTING_OR_SUBSCRIPTION, - PaymentPhase: craftgate.AUTH, + Currency: craftgate.Currency_TRY, + PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION, + PaymentPhase: craftgate.PaymentPhase_AUTH, ConversationId: "foo-bar", ExternalId: "115", Items: []craftgate.PaymentItem{ @@ -313,9 +313,9 @@ func TestPayment_CreateFundTransferDepositPayment(t *testing.T) { func TestPayment_InitDepositApmPayment(t *testing.T) { request := adapter.InitApmDepositPaymentRequest{ - ApmType: craftgate.ApmTypePAPARA, + ApmType: craftgate.ApmType_PAPARA, Price: 1.25, - Currency: craftgate.TRY, + Currency: craftgate.Currency_TRY, BuyerMemberId: 1, ConversationId: "foo-bar", CallbackUrl: "https://www.your-website.com/callback", @@ -333,8 +333,8 @@ func TestPayment_InitGarantiPayPayment(t *testing.T) { request := adapter.InitGarantiPayPaymentRequest{ Price: 100, PaidPrice: 100, - Currency: craftgate.TRY, - PaymentGroup: craftgate.LISTING_OR_SUBSCRIPTION, + Currency: craftgate.Currency_TRY, + PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION, ConversationId: "456d1297-908e-4bd6-a13b-4be31a6e47d5", CallbackUrl: "https://www.your-website.com/craftgate-garantipay-callback", Items: []craftgate.PaymentItem{ @@ -370,11 +370,11 @@ func TestPayment_InitGarantiPayPayment(t *testing.T) { func TestPayment_InitApmPayment(t *testing.T) { request := adapter.InitApmPaymentRequest{ - ApmType: craftgate.ApmTypeEDENRED, + ApmType: craftgate.ApmType_EDENRED, Price: 1.25, PaidPrice: 1.25, - Currency: craftgate.TRY, - PaymentGroup: craftgate.LISTING_OR_SUBSCRIPTION, + Currency: craftgate.Currency_TRY, + PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION, ConversationId: "foo-bar", ApmUserIdentity: "4242424242424242", CallbackUrl: "https://www.your-website.com/callback", @@ -401,11 +401,11 @@ func TestPayment_InitApmPayment(t *testing.T) { func TestPayment_InitKlarnaApmPayment(t *testing.T) { request := adapter.InitApmPaymentRequest{ - ApmType: craftgate.ApmTypeKLARNA, + ApmType: craftgate.ApmType_KLARNA, Price: 1, PaidPrice: 1, - Currency: craftgate.USD, - PaymentGroup: craftgate.LISTING_OR_SUBSCRIPTION, + Currency: craftgate.Currency_USD, + PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION, ConversationId: "foo-bar", CallbackUrl: "https://www.your-website.com/callback", Items: []craftgate.PaymentItem{ @@ -433,11 +433,11 @@ func TestPayment_InitKlarnaApmPayment(t *testing.T) { func TestPayment_InitAfterpayApmPayment(t *testing.T) { request := adapter.InitApmPaymentRequest{ - ApmType: craftgate.ApmTypeAFTERPAY, + ApmType: craftgate.ApmType_AFTERPAY, Price: 1, PaidPrice: 1, - Currency: craftgate.USD, - PaymentGroup: craftgate.LISTING_OR_SUBSCRIPTION, + Currency: craftgate.Currency_USD, + PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION, ConversationId: "foo-bar", CallbackUrl: "https://www.your-website.com/callback", Items: []craftgate.PaymentItem{ @@ -461,11 +461,11 @@ func TestPayment_InitAfterpayApmPayment(t *testing.T) { func TestPayment_InitKaspiApmPayment(t *testing.T) { request := adapter.InitApmPaymentRequest{ - ApmType: craftgate.ApmTypeKASPI, + ApmType: craftgate.ApmType_KASPI, Price: 1, PaidPrice: 1, - Currency: craftgate.KZT, - PaymentGroup: craftgate.LISTING_OR_SUBSCRIPTION, + Currency: craftgate.Currency_KZT, + PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION, ConversationId: "foo-bar", CallbackUrl: "https://www.your-website.com/callback", Items: []craftgate.PaymentItem{ @@ -500,6 +500,51 @@ func TestPayment_CompleteApmPayment(t *testing.T) { } } +func TestPayment_InitPosApmPayment(t *testing.T) { + request := adapter.InitPosApmPaymentRequest{ + Price: 1.25, + PaidPrice: 1.25, + Currency: craftgate.Currency_TRY, + PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION, + ConversationId: "foo-bar", + PaymentProvider: craftgate.PosApmPaymentProvider_YKB_WORLD_PAY, + CallbackUrl: "https://www.your-website.com/callback", + Items: []craftgate.PaymentItem{ + { + Name: "Item 1", + Price: 1, + ExternalId: "1", + }, + { + Name: "Item 2", + Price: 0.25, + ExternalId: "2", + }, + }, + AdditionalParams: map[string]string{ + "sourceCode": "WEB2QR", + }, + } + res, err := paymentClient.Payment.InitPosApmPayment(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} + +func TestPayment_CompletePosApmPayment(t *testing.T) { + request := adapter.CompletePosApmPaymentRequest{ + PaymentId: 123, + } + res, err := paymentClient.Payment.CompletePosApmPayment(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} + func TestPayment_RetrieveLoyalties(t *testing.T) { request := adapter.RetrieveLoyaltiesRequest{ CardNumber: "4043080000000003", @@ -520,7 +565,7 @@ func TestPayment_RefundPaymentTransaction(t *testing.T) { PaymentTransactionId: 1, ConversationId: "456d1297-908e-4bd6-a13b-4be31a6e47d5", RefundPrice: 20, - RefundDestinationType: craftgate.RefundDestinationTypePROVIDER, + RefundDestinationType: craftgate.RefundDestinationType_PROVIDER, } res, err := paymentClient.Payment.RefundPaymentTransaction(context.Background(), request) @@ -543,7 +588,7 @@ func TestPayment_RetrievePaymentTransactionRefund(t *testing.T) { func TestPayment_RefundPayment(t *testing.T) { request := adapter.RefundPaymentRequest{ PaymentId: 1, - RefundDestinationType: craftgate.RefundDestinationTypePROVIDER, + RefundDestinationType: craftgate.RefundDestinationType_PROVIDER, } res, err := paymentClient.Payment.RefundPayment(context.Background(), request) _, _ = spew.Printf("%#v\n", res) @@ -610,8 +655,8 @@ func TestPayment_SearchStoredCards(t *testing.T) { CardAlias: "My YKB Card", CardBankName: "YAPI VE KREDI BANKASI A.S.", CardBrand: "World", - CardType: craftgate.CREDIT_CARD, - CardAssociation: craftgate.MASTER_CARD, + CardType: craftgate.CardType_CREDIT_CARD, + CardAssociation: craftgate.CardAssociation_MASTER_CARD, } res, err := paymentClient.Payment.SearchStoredCards(context.Background(), request) diff --git a/tests/settlement_reporting_test.go b/tests/settlement_reporting_test.go index 4b9bb52..d477e32 100644 --- a/tests/settlement_reporting_test.go +++ b/tests/settlement_reporting_test.go @@ -50,7 +50,7 @@ func TestSettlementReporting_RetrievePayoutDetails(t *testing.T) { func TestSettlementReporting_SearchPayoutRows(t *testing.T) { request := adapter.SearchPayoutRowRequest{ - FileStatus: craftgate.FileStatusCREATED, + FileStatus: craftgate.FileStatus_CREATED, StartDate: time.Now().AddDate(0, 0, -180), EndDate: time.Now(), } diff --git a/tests/settlement_test.go b/tests/settlement_test.go index 9708ef0..5fe1c8b 100644 --- a/tests/settlement_test.go +++ b/tests/settlement_test.go @@ -23,10 +23,10 @@ func TestSettlement_CreateInstantWalletSettlement(t *testing.T) { func TestSettlement_CreateMerchantPayoutAccount(t *testing.T) { request := adapter.CreatePayoutAccountRequest{ - AccountType: craftgate.PayoutAccountTypeWISE, + AccountType: craftgate.PayoutAccountType_WISE, ExternalAccountId: "wiseRecipientId", - Currency: craftgate.USD, - AccountOwner: craftgate.AccountOwnerMERCHANT, + Currency: craftgate.Currency_USD, + AccountOwner: craftgate.AccountOwner_MERCHANT, } res, err := settlementClient.Settlement.CreatePayoutAccount(context.Background(), request) @@ -39,10 +39,10 @@ func TestSettlement_CreateMerchantPayoutAccount(t *testing.T) { func TestSettlement_CreateSubMerchantPayoutAccount(t *testing.T) { request := adapter.CreatePayoutAccountRequest{ - AccountType: craftgate.PayoutAccountTypeWISE, + AccountType: craftgate.PayoutAccountType_WISE, ExternalAccountId: "wiseRecipientId", - Currency: craftgate.EUR, - AccountOwner: craftgate.AccountOwnerSUB_MERCHANT_MEMBER, + Currency: craftgate.Currency_EUR, + AccountOwner: craftgate.AccountOwner_SUB_MERCHANT_MEMBER, SubMerchantMemberId: 1, } @@ -56,7 +56,7 @@ func TestSettlement_CreateSubMerchantPayoutAccount(t *testing.T) { func TestSettlement_UpdatePayoutAccount(t *testing.T) { request := adapter.UpdatePayoutAccountRequest{ - AccountType: craftgate.PayoutAccountTypeWISE, + AccountType: craftgate.PayoutAccountType_WISE, ExternalAccountId: "wiseRecipientId2", } @@ -77,8 +77,8 @@ func TestSettlement_DeletePayoutAccount(t *testing.T) { func TestSettlement_SearchPayoutAccounts(t *testing.T) { request := adapter.SearchPayoutAccountRequest{ - Currency: craftgate.USD, - AccountOwner: craftgate.AccountOwnerMERCHANT, + Currency: craftgate.Currency_USD, + AccountOwner: craftgate.AccountOwner_MERCHANT, } res, err := settlementClient.Settlement.SearchPayoutAccounts(context.Background(), request) diff --git a/tests/wallet_test.go b/tests/wallet_test.go index 1a1a9ba..270ec5e 100644 --- a/tests/wallet_test.go +++ b/tests/wallet_test.go @@ -1,194 +1,194 @@ 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" - "testing" - "time" + "context" + "github.com/craftgate/craftgate-go-client/adapter" + craftgate "github.com/craftgate/craftgate-go-client/adapter" + "github.com/davecgh/go-spew/spew" + "testing" + "time" ) var walletClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io") func TestWallet_RetrieveMemberWallet(t *testing.T) { - res, err := walletClient.Wallet.RetrieveMemberWallet(context.Background(), 1) - _, _ = spew.Printf("%#v\n", res) + res, err := walletClient.Wallet.RetrieveMemberWallet(context.Background(), 1) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } func TestWallet_RetrieveMerchantMemberWallet(t *testing.T) { - res, err := walletClient.Wallet.RetrieveMerchantMemberWallet(context.Background()) - _, _ = spew.Printf("%#v\n", res) + res, err := walletClient.Wallet.RetrieveMerchantMemberWallet(context.Background()) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err) - } + if err != nil { + t.Errorf("Error %s", err) + } } func TestWallet_ResetMerchantMemberWalletBalance(t *testing.T) { - request := adapter.ResetMerchantMemberWalletBalanceRequest{WalletAmount: -10} - res, err := walletClient.Wallet.ResetMerchantMemberWalletBalance(context.Background(), request) - _, _ = spew.Printf("%#v\n", res) + request := adapter.ResetMerchantMemberWalletBalanceRequest{WalletAmount: -10} + res, err := walletClient.Wallet.ResetMerchantMemberWalletBalance(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err.Error()) - } + if err != nil { + t.Errorf("Error %s", err.Error()) + } } func TestWallet_SearchWalletTransactions(t *testing.T) { - request := adapter.SearchWalletTransactionsRequest{ - WalletTransactionTypes: []craftgate.WalletTransactionType{craftgate.DEPOSIT_FROM_CARD}, - } - res, err := walletClient.Wallet.SearchWalletTransactions(context.Background(), 1, request) - _, _ = spew.Printf("%#v\n", res) + request := adapter.SearchWalletTransactionsRequest{ + WalletTransactionTypes: []craftgate.WalletTransactionType{craftgate.WalletTransactionType_DEPOSIT_FROM_CARD}, + } + res, err := walletClient.Wallet.SearchWalletTransactions(context.Background(), 1, request) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err.Error()) - } + if err != nil { + t.Errorf("Error %s", err.Error()) + } } func TestWallet_RetrieveRefundableAmountOfWalletTransaction(t *testing.T) { - res, err := walletClient.Wallet.RetrieveRefundableAmountOfWalletTransaction(context.Background(), 1) - _, _ = spew.Printf("%#v\n", res) + res, err := walletClient.Wallet.RetrieveRefundableAmountOfWalletTransaction(context.Background(), 1) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err.Error()) - } + if err != nil { + t.Errorf("Error %s", err.Error()) + } } func TestWallet_RefundWalletTransaction(t *testing.T) { - request := adapter.RefundWalletTransactionRequest{RefundPrice: 10} - res, err := walletClient.Wallet.RefundWalletTransaction(context.Background(), 1, request) - _, _ = spew.Printf("%#v\n", res) + request := adapter.RefundWalletTransactionRequest{RefundPrice: 10} + res, err := walletClient.Wallet.RefundWalletTransaction(context.Background(), 1, request) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err.Error()) - } + if err != nil { + t.Errorf("Error %s", err.Error()) + } } func TestWallet_RetrieveRefundWalletTransactions(t *testing.T) { - res, err := walletClient.Wallet.RetrieveRefundWalletTransactions(context.Background(), 1) - _, _ = spew.Printf("%#v\n", res) + res, err := walletClient.Wallet.RetrieveRefundWalletTransactions(context.Background(), 1) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err.Error()) - } + if err != nil { + t.Errorf("Error %s", err.Error()) + } } func TestWallet_SendRemittance(t *testing.T) { - request := adapter.RemittanceRequest{ - Price: 100, - MemberId: 1, - Description: "bonus", - RemittanceReasonType: "REDEEM_ONLY_LOYALTY", - } - res, err := walletClient.Wallet.SendRemittance(context.Background(), request) - _, _ = spew.Printf("%#v\n", res) + request := adapter.RemittanceRequest{ + Price: 100, + MemberId: 1, + Description: "bonus", + RemittanceReasonType: "REDEEM_ONLY_LOYALTY", + } + res, err := walletClient.Wallet.SendRemittance(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err.Error()) - } + if err != nil { + t.Errorf("Error %s", err.Error()) + } } func TestWallet_ReceiveRemittance(t *testing.T) { - request := adapter.RemittanceRequest{ - Price: 10, - MemberId: 1, - Description: "bonus", - RemittanceReasonType: "REDEEM_ONLY_LOYALTY", - } - res, err := walletClient.Wallet.ReceiveRemittance(context.Background(), request) - _, _ = spew.Printf("%#v\n", res) + request := adapter.RemittanceRequest{ + Price: 10, + MemberId: 1, + Description: "bonus", + RemittanceReasonType: "REDEEM_ONLY_LOYALTY", + } + res, err := walletClient.Wallet.ReceiveRemittance(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err.Error()) - } + if err != nil { + t.Errorf("Error %s", err.Error()) + } } func TestWallet_RetrieveRemittance(t *testing.T) { - res, err := walletClient.Wallet.RetrieveRemittance(context.Background(), 1) - _, _ = spew.Printf("%#v\n", res) + res, err := walletClient.Wallet.RetrieveRemittance(context.Background(), 1) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err.Error()) - } + if err != nil { + t.Errorf("Error %s", err.Error()) + } } func TestWallet_CreateWithdraw(t *testing.T) { - request := adapter.CreateWithdrawRequest{ - Price: 5, - MemberId: 1, - Description: "Para çekme talebi", - Currency: "TRY", - } - res, err := walletClient.Wallet.CreateWithdraw(context.Background(), request) - _, _ = spew.Printf("%#v\n", res) + request := adapter.CreateWithdrawRequest{ + Price: 5, + MemberId: 1, + Description: "Para çekme talebi", + Currency: "TRY", + } + res, err := walletClient.Wallet.CreateWithdraw(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err.Error()) - } + if err != nil { + t.Errorf("Error %s", err.Error()) + } } func TestWallet_CancelWithdraw(t *testing.T) { - res, err := walletClient.Wallet.CancelWithdraw(context.Background(), 1) - _, _ = spew.Printf("%#v\n", res) + res, err := walletClient.Wallet.CancelWithdraw(context.Background(), 1) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err.Error()) - } + if err != nil { + t.Errorf("Error %s", err.Error()) + } } func TestWallet_RetrieveWithdraw(t *testing.T) { - res, err := walletClient.Wallet.RetrieveWithdraw(context.Background(), 1) - _, _ = spew.Printf("%#v\n", res) + res, err := walletClient.Wallet.RetrieveWithdraw(context.Background(), 1) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err.Error()) - } + if err != nil { + t.Errorf("Error %s", err.Error()) + } } func TestWallet_SearchWithdraws(t *testing.T) { - request := adapter.SearchWithdrawsRequest{ - Currency: "TRY", - MinWithdrawPrice: 0, - MaxWithdrawPrice: 10000, - MinCreatedDate: time.Now().AddDate(0, 0, -180), - MaxCreatedDate: time.Now(), - } - res, err := walletClient.Wallet.SearchWithdraws(context.Background(), request) + request := adapter.SearchWithdrawsRequest{ + Currency: "TRY", + MinWithdrawPrice: 0, + MaxWithdrawPrice: 10000, + MinCreatedDate: time.Now().AddDate(0, 0, -180), + MaxCreatedDate: time.Now(), + } + res, err := walletClient.Wallet.SearchWithdraws(context.Background(), request) - _, _ = spew.Printf("%#v\n", res) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err.Error()) - } + if err != nil { + t.Errorf("Error %s", err.Error()) + } } func TestWallet_CreateMemberWallet(t *testing.T) { - request := adapter.CreateMemberWalletRequest{ - NegativeAmountLimit: 0, - Currency: "TRY", - } - res, err := walletClient.Wallet.CreateMemberWallet(context.Background(), 1, request) - _, _ = spew.Printf("%#v\n", res) + request := adapter.CreateMemberWalletRequest{ + NegativeAmountLimit: 0, + Currency: "TRY", + } + res, err := walletClient.Wallet.CreateMemberWallet(context.Background(), 1, request) + _, _ = spew.Printf("%#v\n", res) - if err != nil { - t.Errorf("Error %s", err.Error()) - } + if err != nil { + t.Errorf("Error %s", err.Error()) + } } func TestWallet_UpdateMemberWallet(t *testing.T) { - request := adapter.UpdateMemberWalletRequest{ - NegativeAmountLimit: -10, - } - res, err := walletClient.Wallet.UpdateMemberWallet(context.Background(), 1, 1, request) - _, _ = spew.Printf("%#v\n", res) - - if err != nil { - t.Errorf("Error %s", err.Error()) - } + request := adapter.UpdateMemberWalletRequest{ + NegativeAmountLimit: -10, + } + res, err := walletClient.Wallet.UpdateMemberWallet(context.Background(), 1, 1, request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err.Error()) + } } From c12ce29b7a083bb1a6dadb74d7de25316875186f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alican=20Akku=C5=9F?= Date: Fri, 13 Oct 2023 10:26:30 +0300 Subject: [PATCH 03/30] adds payout date as a settlement completed date while retrieving payout detail (#50) --- adapter/model.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/adapter/model.go b/adapter/model.go index 65a97c6..853bed0 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -1511,15 +1511,16 @@ type RetrievePayoutDetailsRequest struct { } type SearchPayoutCompletedTransactionsResponse struct { - PayoutId *int64 `json:"payoutId"` - TransactionId *int64 `json:"transactionId"` - TransactionType *string `json:"transactionType"` - PayoutAmount *float64 `json:"payoutAmount"` - Currency *Currency `json:"currency"` - MerchantId *int64 `json:"merchantId"` - MerchantType *string `json:"merchantType"` - SettlementEarningsDestination *string `json:"settlementEarningsDestination"` - SettlementSource *string `json:"settlementSource"` + PayoutId *int64 `json:"payoutId"` + TransactionId *int64 `json:"transactionId"` + TransactionType *string `json:"transactionType"` + PayoutAmount *float64 `json:"payoutAmount"` + PayoutDate *TimeResponse `json:"payoutDate"` + Currency *Currency `json:"currency"` + MerchantId *int64 `json:"merchantId"` + MerchantType *string `json:"merchantType"` + SettlementEarningsDestination *string `json:"settlementEarningsDestination"` + SettlementSource *string `json:"settlementSource"` } type SearchPayoutBouncedTransactionsResponse struct { From 4362e26207bad89b1357ab1925848914e670bed9 Mon Sep 17 00:00:00 2001 From: Avni BALIKCI <108258717+abalikci@users.noreply.github.com> Date: Tue, 31 Oct 2023 12:51:14 +0200 Subject: [PATCH 04/30] Adds tompay integration (#52) --- adapter/model.go | 11 ++++++++--- tests/payment_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/adapter/model.go b/adapter/model.go index 853bed0..9277308 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -76,6 +76,7 @@ const ( ApmType_KLARNA ApmType = "KLARNA" ApmType_AFTERPAY ApmType = "AFTERPAY" ApmType_KASPI ApmType = "KASPI" + ApmType_TOMPAY ApmType = "TOMPAY" ApmType_STRIPE ApmType = "STRIPE" ApmType_FUND_TRANSFER ApmType = "FUND_TRANSFER" ApmType_CASH_ON_DELIVERY ApmType = "CASH_ON_DELIVERY" @@ -97,6 +98,7 @@ const ( PaymentProvider_KLARNA PaymentProvider = "KLARNA" PaymentProvider_AFTERPAY PaymentProvider = "AFTERPAY" PaymentProvider_KASPI PaymentProvider = "KASPI" + PaymentProvider_TOMPAY PaymentProvider = "TOMPAY" PaymentProvider_APPLEPAY PaymentProvider = "APPLEPAY" PaymentProvider_GOOGLEPAY PaymentProvider = "GOOGLEPAY" PaymentProvider_HEPSIPAY PaymentProvider = "HEPSIPAY" @@ -169,6 +171,7 @@ const ( PaymentMethod_KLARNA PaymentMethod = "KLARNA" PaymentMethod_AFTERPAY PaymentMethod = "AFTERPAY" PaymentMethod_KASPI PaymentMethod = "KASPI" + PaymentMethod_TOMPAY PaymentMethod = "TOMPAY" PaymentMethod_STRIPE PaymentMethod = "STRIPE" ) @@ -316,9 +319,11 @@ const ( // apm additional action type declaration const ( - ApmAdditionalAction_REDIRECT_TO_URL ApmAdditionalAction = "REDIRECT_TO_URL" - ApmAdditionalAction_OTP_REQUIRED ApmAdditionalAction = "OTP_REQUIRED" - ApmAdditionalAction_NONE ApmAdditionalAction = "NONE" + ApmAdditionalAction_REDIRECT_TO_URL ApmAdditionalAction = "REDIRECT_TO_URL" + ApmAdditionalAction_OTP_REQUIRED ApmAdditionalAction = "OTP_REQUIRED" + ApmAdditionalAction_WAIT_FOR_WEBHOOK ApmAdditionalAction = "WAIT_FOR_WEBHOOK" + ApmAdditionalAction_APPROVAL_REQUIRED ApmAdditionalAction = "APPROVAL_REQUIRED" + ApmAdditionalAction_NONE ApmAdditionalAction = "NONE" ) // report file type declaration diff --git a/tests/payment_test.go b/tests/payment_test.go index c0ade50..ff3346a 100644 --- a/tests/payment_test.go +++ b/tests/payment_test.go @@ -487,6 +487,39 @@ func TestPayment_InitKaspiApmPayment(t *testing.T) { } } +func TestPayment_InitTompayApmPayment(t *testing.T) { + additionalParams := make(map[string]string) + additionalParams["phone"] = "phone" + additionalParams["channel"] = "channel" + + request := adapter.InitApmPaymentRequest{ + ApmType: craftgate.ApmType_TOMPAY, + Price: 1, + PaidPrice: 1, + Currency: craftgate.Currency_TRY, + PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION, + ConversationId: "foo-bar", + CallbackUrl: "https://www.your-website.com/callback", + Items: []craftgate.PaymentItem{ + { + Name: "Item 1", + Price: 0.6, + }, + { + Name: "Item 2", + Price: 0.4, + }, + }, + AdditionalParams: additionalParams, + } + res, err := paymentClient.Payment.InitApmPayment(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} + func TestPayment_CompleteApmPayment(t *testing.T) { request := adapter.CompleteApmPaymentRequest{ PaymentId: 123, From 71e242c41825f175e6aa42629c81de8f0abd1a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alican=20Akku=C5=9F?= Date: Fri, 10 Nov 2023 12:03:19 +0300 Subject: [PATCH 05/30] adds bank account tracking adapter to retrieve bank account tracking record (#41) --- adapter/bank_account_tracking.go | 41 +++++++++++++++++++++++++++++ adapter/craftgate.go | 2 ++ adapter/model.go | 37 ++++++++++++++++++++++++++ tests/bank_account_tracking_test.go | 35 ++++++++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 adapter/bank_account_tracking.go create mode 100644 tests/bank_account_tracking_test.go diff --git a/adapter/bank_account_tracking.go b/adapter/bank_account_tracking.go new file mode 100644 index 0000000..7b8bb64 --- /dev/null +++ b/adapter/bank_account_tracking.go @@ -0,0 +1,41 @@ +package adapter + +import ( + "context" + "fmt" + "net/http" +) + +type BankAccountTracking struct { + Client *Client +} + +func (api *BankAccountTracking) SearchRecords(ctx context.Context, request SearchBankAccountTrackingRecordRequest) (*DataResponse[BankAccountTrackingRecordResponse], error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, "/bank-account-tracking/v1/merchant-bank-account-trackings/records", request) + if err != nil { + return nil, err + } + response := &Response[DataResponse[BankAccountTrackingRecordResponse]]{} + err = api.Client.Do(ctx, newRequest, response) + + if err != nil { + return nil, err + } + + return response.Data, nil +} + +func (api *BankAccountTracking) RetrieveRecords(ctx context.Context, id int64) (*BankAccountTrackingRecordResponse, error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("/bank-account-tracking/v1/merchant-bank-account-trackings/records/%d", id), nil) + if err != nil { + return nil, err + } + response := &Response[BankAccountTrackingRecordResponse]{} + err = api.Client.Do(ctx, newRequest, response) + + if err != nil { + return nil, err + } + + return response.Data, nil +} diff --git a/adapter/craftgate.go b/adapter/craftgate.go index 9f5b994..2566460 100644 --- a/adapter/craftgate.go +++ b/adapter/craftgate.go @@ -84,6 +84,7 @@ type Client struct { Fraud *Fraud Hook *Hook Masterpass *Masterpass + BankAccountTracking *BankAccountTracking } func New(apiKey, apiSecret, baseURL string, opts ...ClientOption) (*Client, error) { @@ -119,6 +120,7 @@ func newClient(apiKey, secretKey string) *Client { client.Fraud = &Fraud{Client: client} client.Hook = &Hook{Client: client} client.Masterpass = &Masterpass{Client: client} + client.BankAccountTracking = &BankAccountTracking{Client: client} return client } diff --git a/adapter/model.go b/adapter/model.go index 9277308..0552eb6 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -44,6 +44,8 @@ type PosOperationType string type FileStatus string type AccountOwner string type PayoutAccountType string +type RecordType string +type BankAccountTrackingSource string const ( ApiKeyHeaderName = "x-api-key" @@ -441,6 +443,17 @@ const ( PayoutAccountType_WISE PayoutAccountType = "WISE" ) +// RecordType declaration +const ( + RecordType_SEND RecordType = "SEND" + RecordType_RECEIVE RecordType = "RECEIVE" +) + +// BankAccountTrackingSource declaration +const ( + BankAccountTrackingSource_YKB BankAccountTrackingSource = "YKB" +) + // requests type CreatePaymentRequest struct { Price float64 `json:"price,omitempty"` @@ -1637,6 +1650,30 @@ type WebhookData struct { PayloadId string } +type SearchBankAccountTrackingRecordRequest struct { + SenderName string `schema:"senderName,omitempty"` + SenderIban string `schema:"senderIban,omitempty"` + Description string `schema:"description,omitempty"` + Currency Currency `schema:"currency,omitempty"` + MinRecordDate time.Time `schema:"minRecordDate,omitempty"` + MaxRecordDate time.Time `schema:"maxRecordDate,omitempty"` + Page int `schema:"page,omitempty"` + Size int `schema:"size,omitempty"` +} + +type BankAccountTrackingRecordResponse struct { + Id int64 `json:"id"` + Key string `json:"key"` + SenderName string `json:"senderName"` + SenderIban string `json:"senderIban"` + Description string `json:"description"` + Currency Currency `json:"currency"` + Amount float64 `json:"amount"` + RecordDate TimeResponse `json:"recordDate"` + RecordType RecordType `json:"recordType"` + BankAccountTrackingSource BankAccountTrackingSource `json:"bankAccountTrackingSource"` +} + type RequestOptions struct { BaseURL string ApiKey string diff --git a/tests/bank_account_tracking_test.go b/tests/bank_account_tracking_test.go new file mode 100644 index 0000000..841f9f9 --- /dev/null +++ b/tests/bank_account_tracking_test.go @@ -0,0 +1,35 @@ +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" + "testing" +) + +var bankAccountTrackingClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io") + +func TestBankAccountTracking_SearchBankAccountTrackingRecords(t *testing.T) { + request := adapter.SearchBankAccountTrackingRecordRequest{ + Page: 0, + Size: 10, + Currency: craftgate.Currency_TRY, + } + + res, err := bankAccountTrackingClient.BankAccountTracking.SearchRecords(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} + +func TestBankAccountTracking_RetrieveRecord(t *testing.T) { + res, err := bankAccountTrackingClient.BankAccountTracking.RetrieveRecords(context.Background(), 1) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} From b888490279db46bfe48c4901b9535770c7c9f44c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Derya=20=C3=87akmak?= <36774966+deryacakmak@users.noreply.github.com> Date: Tue, 14 Nov 2023 19:40:03 +0200 Subject: [PATCH 06/30] bnpl payment integration (#54) * bnpl payment integration * bnpl payment integration * bnpl payment integration * bnpl payment integration * bnpl payment integration * updates based on comments * updates based on comments * updates based on comments * updates based on comments * updates based on comments --- adapter/model.go | 104 ++++++++++++++++++++++++++++++++++++++++++ adapter/payment.go | 45 ++++++++++++++++++ tests/payment_test.go | 91 ++++++++++++++++++++++++++++++++++++ 3 files changed, 240 insertions(+) diff --git a/adapter/model.go b/adapter/model.go index 0552eb6..c751aab 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -46,6 +46,7 @@ type AccountOwner string type PayoutAccountType string type RecordType string type BankAccountTrackingSource string +type BnplCartItemType string const ( ApiKeyHeaderName = "x-api-key" @@ -79,6 +80,8 @@ const ( ApmType_AFTERPAY ApmType = "AFTERPAY" ApmType_KASPI ApmType = "KASPI" ApmType_TOMPAY ApmType = "TOMPAY" + ApmType_MASLAK ApmType = "MASLAK" + ApmType_ALFABANK ApmType = "ALFABANK" ApmType_STRIPE ApmType = "STRIPE" ApmType_FUND_TRANSFER ApmType = "FUND_TRANSFER" ApmType_CASH_ON_DELIVERY ApmType = "CASH_ON_DELIVERY" @@ -443,6 +446,34 @@ const ( PayoutAccountType_WISE PayoutAccountType = "WISE" ) +// BnplCartItemType type declaration +const ( + BnplCartItemType_MOBILE_PHONE_OVER_5000_TRY BnplCartItemType = "MOBILE_PHONE_OVER_5000_TRY" + BnplCartItemType_MOBILE_PHONE_BELOW_5000_TRY BnplCartItemType = "MOBILE_PHONE_BELOW_5000_TRY" + BnplCartItemType_TABLET BnplCartItemType = "TABLET" + BnplCartItemType_COMPUTER BnplCartItemType = "COMPUTER" + BnplCartItemType_CONSTRUCTION_MARKET BnplCartItemType = "CONSTRUCTION_MARKET" + BnplCartItemType_GOLD BnplCartItemType = "GOLD" + BnplCartItemType_DIGITAL_PRODUCTS BnplCartItemType = "DIGITAL_PRODUCTS" + BnplCartItemType_SUPERMARKET BnplCartItemType = "SUPERMARKET" + BnplCartItemType_WHITE_GOODS BnplCartItemType = "WHITE_GOODS" + BnplCartItemType_WEARABLE_TECHNOLOGY BnplCartItemType = "WEARABLE_TECHNOLOGY" + BnplCartItemType_SMALL_HOME_APPLIANCES BnplCartItemType = "SMALL_HOME_APPLIANCES" + BnplCartItemType_TV BnplCartItemType = "TV" + BnplCartItemType_GAMES_CONSOLES BnplCartItemType = "GAMES_CONSOLES" + BnplCartItemType_AIR_CONDITIONER_AND_HEATER BnplCartItemType = "AIR_CONDITIONER_AND_HEATER" + BnplCartItemType_ELECTRONICS BnplCartItemType = "ELECTRONICS" + BnplCartItemType_ACCESSORIES BnplCartItemType = "ACCESSORIES" + BnplCartItemType_MOM_AND_BABY_AND_KIDS BnplCartItemType = "MOM_AND_BABY_AND_KIDS" + BnplCartItemType_SHOES BnplCartItemType = "SHOES" + BnplCartItemType_CLOTHING BnplCartItemType = "CLOTHING" + BnplCartItemType_COSMETICS_AND_PERSONAL_CARE BnplCartItemType = "COSMETICS_AND_PERSONAL_CARE" + BnplCartItemType_FURNITURE BnplCartItemType = "FURNITURE" + BnplCartItemType_HOME_LIVING BnplCartItemType = "HOME_LIVING" + BnplCartItemType_AUTOMOBILE_MOTORCYCLE BnplCartItemType = "AUTOMOBILE_MOTORCYCLE" + BnplCartItemType_OTHER BnplCartItemType = "OTHER" +) + // RecordType declaration const ( RecordType_SEND RecordType = "SEND" @@ -768,6 +799,47 @@ type MasterpassPaymentThreeDSCompleteRequest struct { PaymentId int64 `json:"paymentId,omitempty"` } +type InitBnplPaymentRequest struct { + ApmType ApmType `json:"apmType"` + MerchantApmId int64 `json:"merchantApmId,omitempty"` + Price float64 `json:"price"` + PaidPrice float64 `json:"paidPrice"` + CommissionRate float64 `json:"commissionRate,omitempty"` + Currency Currency `json:"currency"` + PaymentType PaymentType `json:"paymentType"` + PaymentGroup PaymentGroup `json:"paymentGroup"` + PaymentSource PaymentSource `json:"paymentSource,omitempty"` + PaymentChannel string `json:"paymentChannel,omitempty"` + ConversationId string `json:"conversationId,omitempty"` + ExternalId string `json:"externalId,omitempty"` + CallbackUrl string `json:"callbackUrl"` + BuyerMemberId int64 `json:"buyerMemberId,omitempty"` + ApmOrderId string `json:"apmOrderId,omitempty"` + ClientIp string `json:"clientIp,omitempty"` + ApmUserIdentity string `json:"apmUserIdentity,omitempty"` + AdditionalParams map[string]interface{} `json:"additionalParams"` + Items []PaymentItem `json:"items"` + BankCode string `json:"bankCode"` + CartItems []BnplPaymentCartItem `json:"cartItems"` +} + +type BnplPaymentCartItem struct { + Id string `json:"id"` + Name string `json:"name"` + BrandName string `json:"brandName"` + Type BnplCartItemType `json:"type"` + UnitPrice float64 `json:"unitPrice"` + Quantity int64 `json:"quantity"` +} + +type BnplPaymentOfferRequest struct { + ApmType ApmType `json:"apmType"` + MerchantApmId int64 `json:"merchantApmId,omitempty"` + Price float64 `json:"price"` + Currency Currency `json:"currency"` + Items []BnplPaymentCartItem `json:"items"` +} + // responses type PaymentResponse struct { Id *int64 `json:"id"` @@ -1481,6 +1553,38 @@ type ReportingPaymentTransactionResponse struct { PayoutStatus *PayoutStatus `json:"payoutStatus"` } +type InitBnplPaymentResponse struct { + PaymentId int64 `json:"paymentId"` + RedirectUrl string `json:"redirectUrl"` + PaymentStatus PaymentStatus `json:"paymentStatus"` + AdditionalAction ApmAdditionalAction `json:"additionalAction"` + PaymentError PaymentError `json:"paymentError"` +} + +type BnplPaymentOfferResponse struct { + OfferId string `json:"offerId"` + Price *float64 `json:"price"` + BnplBankOffers *[]BnplBankOffer `json:"nnplBankOffers"` +} + +type BnplBankOffer struct { + BankCode string `json:"bankCode"` + BankName string `json:"bankName"` + BankIconUrl string `json:"bankIconUrl"` + BankTableBannerMessage string `json:"bankTableBannerMessage"` + BankSmallBannerMessage string `json:"bankSmallBannerMessage"` + IsSupportNonCustomer bool `json:"isSupportNonCustomer"` + BnplBankOfferTerm *[]BnplBankOfferTerm `json:"bankOfferTerms"` +} + +type BnplBankOfferTerm struct { + Term int64 `json:"term"` + Amount *float64 `json:"amount"` + TotalAmount *float64 `json:"totalAmount"` + InterestRate *float64 `json:"interestRate"` + AnnualInterestRate *float64 `json:"annualInterestRate"` +} + type Payout struct { PaidPrice *float64 `json:"paidPrice"` Parity *float64 `json:"parity"` diff --git a/adapter/payment.go b/adapter/payment.go index 0053931..5ca00ea 100644 --- a/adapter/payment.go +++ b/adapter/payment.go @@ -508,6 +508,51 @@ func (api *Payment) DisapprovePaymentTransactions(ctx context.Context, request P return response.Data, nil } +func (api *Payment) RetrieveBnplOffers(ctx context.Context, request BnplPaymentOfferRequest) (*DataResponse[BnplPaymentOfferResponse], error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/bnpl-payments/offers", request) + if err != nil { + return nil, err + } + + response := &Response[DataResponse[BnplPaymentOfferResponse]]{} + err = api.Client.Do(ctx, newRequest, response) + if err != nil { + return nil, err + } + + return response.Data, nil +} + +func (api *Payment) InitBnplPayment(ctx context.Context, request InitBnplPaymentRequest) (*InitBnplPaymentResponse, error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/bnpl-payments/init", request) + if err != nil { + return nil, err + } + response := &Response[InitBnplPaymentResponse]{} + err = api.Client.Do(ctx, newRequest, response) + if err != nil { + return nil, err + } + + return response.Data, nil +} + +func (api *Payment) ApproveBnplPayment(ctx context.Context, paymentId int64) error { + + newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, fmt.Sprintf("/payment/v1/bnpl-payments/%d/approve", paymentId), nil) + if err != nil { + return err + } + + response := &Void{} + err = api.Client.Do(ctx, newRequest, response) + if err != nil { + return err + } + + return nil +} + func (c *Payment) Is3DSecureCallbackVerified(threeDSecureCallbackKey string, params map[string]string) bool { hash := params["hash"] hashString := strings.Join([]string{threeDSecureCallbackKey, diff --git a/tests/payment_test.go b/tests/payment_test.go index ff3346a..0970b7d 100644 --- a/tests/payment_test.go +++ b/tests/payment_test.go @@ -770,3 +770,94 @@ func TestPayment_NotVerify3DSCallback(t *testing.T) { require.False(t, is3DSecureCallbackVerified) } + +func TestPayment_BnplPaymentOffer(t *testing.T) { + request := adapter.BnplPaymentOfferRequest{ + ApmType: craftgate.ApmType_MASLAK, + Price: 10000, + Currency: craftgate.Currency_TRY, + Items: []craftgate.BnplPaymentCartItem{ + { + Id: "200", + Name: "Test Elektronik 2", + BrandName: "iphone", + Type: craftgate.BnplCartItemType_MOBILE_PHONE_BELOW_5000_TRY, + UnitPrice: 3000, + Quantity: 2, + }, + { + Id: "100", + Name: "Test Elektronik 1", + BrandName: "Samsung", + Type: craftgate.BnplCartItemType_OTHER, + UnitPrice: 4000, + Quantity: 1, + }, + }, + } + res, err := paymentClient.Payment.RetrieveBnplOffers(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} + +func TestPayment_InitBnplPayment(t *testing.T) { + request := adapter.InitBnplPaymentRequest{ + ApmType: craftgate.ApmType_MASLAK, + Price: 10000, + PaidPrice: 10000, + PaymentType: craftgate.PaymentType_APM, + Currency: craftgate.Currency_TRY, + ApmOrderId: "order_id", + PaymentGroup: craftgate.PaymentGroup_PRODUCT, + ConversationId: "29393-mXld92ko3", + ExternalId: "external_id-345", + CallbackUrl: "callback", + BankCode: "103", + Items: []craftgate.PaymentItem{ + { + Name: "Item 1", + Price: 6000, + ExternalId: "38983903", + }, + { + Name: "Item 2", + Price: 4000, + ExternalId: "92983294", + }, + }, + CartItems: []craftgate.BnplPaymentCartItem{ + { + Id: "200", + Name: "Test Elektronik 2", + BrandName: "iphone", + Type: craftgate.BnplCartItemType_OTHER, + UnitPrice: 3000, + Quantity: 2, + }, + { + Id: "100", + Name: "Test Elektronik 1", + BrandName: "Samsung", + Type: craftgate.BnplCartItemType_MOBILE_PHONE_OVER_5000_TRY, + UnitPrice: 4000, + Quantity: 1, + }, + }, + } + res, err := paymentClient.Payment.InitBnplPayment(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} + +func TestPayment_ApproveBnplPayment(t *testing.T) { + err := paymentClient.Payment.ApproveBnplPayment(context.Background(), 1) + if err != nil { + t.Errorf("Error %s", err) + } +} From 69dda3f2a404cbc91e50f9c4cd0c4e45972bd9e2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 15 Nov 2023 13:51:52 +0300 Subject: [PATCH 07/30] Bump github.com/gorilla/schema from 1.2.0 to 1.2.1 (#53) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [github.com/gorilla/schema](https://github.com/gorilla/schema) from 1.2.0 to 1.2.1. - [Release notes](https://github.com/gorilla/schema/releases) - [Commits](https://github.com/gorilla/schema/compare/v1.2.0...v1.2.1) --- updated-dependencies: - dependency-name: github.com/gorilla/schema dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sabri Onur Tüzün <335067+sotuzun@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 755d04f..5f6e7d0 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( github.com/davecgh/go-spew v1.1.1 - github.com/gorilla/schema v1.2.0 + github.com/gorilla/schema v1.2.1 github.com/stretchr/testify v1.8.4 ) diff --git a/go.sum b/go.sum index 0e93920..e0d170a 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc= -github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU= +github.com/gorilla/schema v1.2.1 h1:tjDxcmdb+siIqkTNoV+qRH2mjYdr2hHe5MKXbp61ziM= +github.com/gorilla/schema v1.2.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= From 90b67da990df2bbb434e4437b939d8cafe1e70b7 Mon Sep 17 00:00:00 2001 From: Burak BALDIRLIOGLU Date: Thu, 23 Nov 2023 17:03:39 +0300 Subject: [PATCH 08/30] adds new event types (#55) --- adapter/model.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/adapter/model.go b/adapter/model.go index c751aab..ba6ab87 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -364,6 +364,13 @@ const ( WebhookEventType_API_VERIFY_AND_AUTH WebhookEventType = "API_VERIFY_AND_AUTH" WebhookEventType_CHECKOUTFORM_AUTH WebhookEventType = "CHECKOUTFORM_AUTH" WebhookEventType_THREEDS_VERIFY WebhookEventType = "THREEDS_VERIFY" + WebhookEventType_REFUND WebhookEventType = "REFUND" + WebhookEventType_REFUND_TX WebhookEventType = "REFUND_TX" + WebhookEventType_PAYOUT_COMPLETED WebhookEventType = "PAYOUT_COMPLETED" + WebhookEventType_AUTOPILOT WebhookEventType = "AUTOPILOT" + WebhookEventType_WALLET_CREATED WebhookEventType = "WALLET_CREATED" + WebhookEventType_WALLET_TX_CREATED WebhookEventType = "WALLET_TX_CREATED" + WebhookEventType_BNPL_NOTIFICATION WebhookEventType = "BNPL_NOTIFICATION" ) const ( From 172034662cff03e6482a9189a743ae2cdb261b8d Mon Sep 17 00:00:00 2001 From: Avni BALIKCI <108258717+abalikci@users.noreply.github.com> Date: Mon, 27 Nov 2023 13:03:17 +0300 Subject: [PATCH 09/30] Adds tom finance (#56) --- adapter/model.go | 43 ++++++++++++++++++++++--------------------- tests/payment_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 21 deletions(-) diff --git a/adapter/model.go b/adapter/model.go index ba6ab87..c272858 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -82,6 +82,7 @@ const ( ApmType_TOMPAY ApmType = "TOMPAY" ApmType_MASLAK ApmType = "MASLAK" ApmType_ALFABANK ApmType = "ALFABANK" + ApmType_TOM_FINANCE ApmType = "TOM_FINANCE" ApmType_STRIPE ApmType = "STRIPE" ApmType_FUND_TRANSFER ApmType = "FUND_TRANSFER" ApmType_CASH_ON_DELIVERY ApmType = "CASH_ON_DELIVERY" @@ -807,27 +808,27 @@ type MasterpassPaymentThreeDSCompleteRequest struct { } type InitBnplPaymentRequest struct { - ApmType ApmType `json:"apmType"` - MerchantApmId int64 `json:"merchantApmId,omitempty"` - Price float64 `json:"price"` - PaidPrice float64 `json:"paidPrice"` - CommissionRate float64 `json:"commissionRate,omitempty"` - Currency Currency `json:"currency"` - PaymentType PaymentType `json:"paymentType"` - PaymentGroup PaymentGroup `json:"paymentGroup"` - PaymentSource PaymentSource `json:"paymentSource,omitempty"` - PaymentChannel string `json:"paymentChannel,omitempty"` - ConversationId string `json:"conversationId,omitempty"` - ExternalId string `json:"externalId,omitempty"` - CallbackUrl string `json:"callbackUrl"` - BuyerMemberId int64 `json:"buyerMemberId,omitempty"` - ApmOrderId string `json:"apmOrderId,omitempty"` - ClientIp string `json:"clientIp,omitempty"` - ApmUserIdentity string `json:"apmUserIdentity,omitempty"` - AdditionalParams map[string]interface{} `json:"additionalParams"` - Items []PaymentItem `json:"items"` - BankCode string `json:"bankCode"` - CartItems []BnplPaymentCartItem `json:"cartItems"` + ApmType ApmType `json:"apmType"` + MerchantApmId int64 `json:"merchantApmId,omitempty"` + Price float64 `json:"price"` + PaidPrice float64 `json:"paidPrice"` + CommissionRate float64 `json:"commissionRate,omitempty"` + Currency Currency `json:"currency"` + PaymentType PaymentType `json:"paymentType"` + PaymentGroup PaymentGroup `json:"paymentGroup"` + PaymentSource PaymentSource `json:"paymentSource,omitempty"` + PaymentChannel string `json:"paymentChannel,omitempty"` + ConversationId string `json:"conversationId,omitempty"` + ExternalId string `json:"externalId,omitempty"` + CallbackUrl string `json:"callbackUrl"` + BuyerMemberId int64 `json:"buyerMemberId,omitempty"` + ApmOrderId string `json:"apmOrderId,omitempty"` + ClientIp string `json:"clientIp,omitempty"` + ApmUserIdentity string `json:"apmUserIdentity,omitempty"` + AdditionalParams map[string]string `json:"additionalParams"` + Items []PaymentItem `json:"items"` + BankCode string `json:"bankCode,omitempty"` + CartItems []BnplPaymentCartItem `json:"cartItems"` } type BnplPaymentCartItem struct { diff --git a/tests/payment_test.go b/tests/payment_test.go index 0970b7d..fe0544a 100644 --- a/tests/payment_test.go +++ b/tests/payment_test.go @@ -855,6 +855,48 @@ func TestPayment_InitBnplPayment(t *testing.T) { } } +func TestPayment_InitTomFinanceBnplPayment(t *testing.T) { + request := adapter.InitBnplPaymentRequest{ + ApmType: craftgate.ApmType_TOM_FINANCE, + Price: 100, + PaidPrice: 100, + PaymentType: craftgate.PaymentType_APM, + Currency: craftgate.Currency_TRY, + ApmOrderId: "myUniqueApmOrderId", + PaymentGroup: craftgate.PaymentGroup_PRODUCT, + ConversationId: "conversationId", + ExternalId: "externalId", + CallbackUrl: "https://www.your-website.com/callback", + Items: []craftgate.PaymentItem{ + { + Name: "Item 1", + Price: 100, + ExternalId: "externalId", + }, + }, + AdditionalParams: map[string]string{ + "buyerName": "John Doe", + "buyerPhoneNumber": "5554443322", + }, + CartItems: []craftgate.BnplPaymentCartItem{ + { + Id: "26020874", + Name: "Test Item 1", + BrandName: "26010303", + Type: craftgate.BnplCartItemType_OTHER, + UnitPrice: 100, + Quantity: 1, + }, + }, + } + res, err := paymentClient.Payment.InitBnplPayment(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} + func TestPayment_ApproveBnplPayment(t *testing.T) { err := paymentClient.Payment.ApproveBnplPayment(context.Background(), 1) if err != nil { From b07f93f3d812d63857c32b1ef3a08d0be45ea4cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alican=20Akku=C5=9F?= Date: Tue, 5 Dec 2023 13:31:03 +0300 Subject: [PATCH 10/30] adds merchant & pos operations (#57) --- adapter/craftgate.go | 2 + adapter/merchant.go | 116 +++++++++++++++++++++++++++ adapter/model.go | 168 ++++++++++++++++++++++++++++++++++++++- adapter/onboarding.go | 15 ++++ tests/merchant_test.go | 128 +++++++++++++++++++++++++++++ tests/onboarding_test.go | 19 +++++ 6 files changed, 446 insertions(+), 2 deletions(-) create mode 100644 adapter/merchant.go create mode 100644 tests/merchant_test.go diff --git a/adapter/craftgate.go b/adapter/craftgate.go index 2566460..06a5fb4 100644 --- a/adapter/craftgate.go +++ b/adapter/craftgate.go @@ -85,6 +85,7 @@ type Client struct { Hook *Hook Masterpass *Masterpass BankAccountTracking *BankAccountTracking + Merchant *Merchant } func New(apiKey, apiSecret, baseURL string, opts ...ClientOption) (*Client, error) { @@ -121,6 +122,7 @@ func newClient(apiKey, secretKey string) *Client { client.Hook = &Hook{Client: client} client.Masterpass = &Masterpass{Client: client} client.BankAccountTracking = &BankAccountTracking{Client: client} + client.Merchant = &Merchant{Client: client} return client } diff --git a/adapter/merchant.go b/adapter/merchant.go new file mode 100644 index 0000000..39b09d1 --- /dev/null +++ b/adapter/merchant.go @@ -0,0 +1,116 @@ +package adapter + +import ( + "context" + "fmt" + "net/http" +) + +type Merchant struct { + Client *Client +} + +func (api *Merchant) CreateMerchantPos(ctx context.Context, request CreateMerchantPosRequest) (*MerchantPosResponse, error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/merchant/v1/merchant-poses", request) + + if err != nil { + return nil, err + } + + response := &Response[MerchantPosResponse]{} + err = api.Client.Do(ctx, newRequest, response) + if err != nil { + return nil, err + } + return response.Data, nil +} + +func (api *Merchant) RetrieveMerchantPos(ctx context.Context, id int64) (*MerchantPosResponse, error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("/merchant/v1/merchant-poses/%d", id), nil) + + if err != nil { + return nil, err + } + + response := &Response[MerchantPosResponse]{} + err = api.Client.Do(ctx, newRequest, response) + if err != nil { + return nil, err + } + return response.Data, nil +} + +func (api *Merchant) SearchMerchantPos(ctx context.Context, request SearchMerchantPosRequest) (*DataResponse[MerchantPosResponse], error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, "/merchant/v1/merchant-poses", request) + + if err != nil { + return nil, err + } + + response := &Response[DataResponse[MerchantPosResponse]]{} + err = api.Client.Do(ctx, newRequest, response) + if err != nil { + return nil, err + } + return response.Data, nil +} + +func (api *Merchant) UpdateMerchantPosStatus(ctx context.Context, id int64, status PosStatus) error { + newRequest, err := api.Client.NewRequest(ctx, http.MethodPut, fmt.Sprintf("/merchant/v1/merchant-poses/%d/status/%s", id, status), nil) + + if err != nil { + return err + } + + response := &Void{} + err = api.Client.Do(ctx, newRequest, response) + if err != nil { + return err + } + return nil +} + +func (api *Merchant) DeleteMerchantPosStatus(ctx context.Context, id int64) error { + newRequest, err := api.Client.NewRequest(ctx, http.MethodDelete, fmt.Sprintf("/merchant/v1/merchant-poses/%d", id), nil) + + if err != nil { + return err + } + + response := &Void{} + err = api.Client.Do(ctx, newRequest, response) + if err != nil { + return err + } + return nil +} + +func (api *Merchant) RetrieveMerchantPosCommissions(ctx context.Context, id int64) (*DataResponse[MerchantPosCommissionResponse], error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("/merchant/v1/merchant-poses/%d/commissions", id), nil) + + if err != nil { + return nil, err + } + + response := &Response[DataResponse[MerchantPosCommissionResponse]]{} + err = api.Client.Do(ctx, newRequest, response) + if err != nil { + return nil, err + } + return response.Data, nil +} + +func (api *Merchant) UpdateMerchantPosCommissions(ctx context.Context, id int64, request CreateMerchantPosCommissionRequest) (*DataResponse[MerchantPosCommissionResponse], error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, fmt.Sprintf("/merchant/v1/merchant-poses/%d/commissions", id), request) + + if err != nil { + return nil, err + } + + response := &Response[DataResponse[MerchantPosCommissionResponse]]{} + err = api.Client.Do(ctx, newRequest, response) + if err != nil { + return nil, err + } + return response.Data, nil +} diff --git a/adapter/model.go b/adapter/model.go index c272858..96aca35 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -47,6 +47,8 @@ type PayoutAccountType string type RecordType string type BankAccountTrackingSource string type BnplCartItemType string +type PaymentAuthenticationType string +type CardBrand string const ( ApiKeyHeaderName = "x-api-key" @@ -394,12 +396,13 @@ const ( PosIntegrator_AKBANK PosIntegrator = "AKBANK" PosIntegrator_ZIRAATBANK PosIntegrator = "ZIRAATBANK" PosIntegrator_ZIRAATBANK_INNOVA PosIntegrator = "ZIRAATBANK_INNOVA" + PosIntegrator_ZIRAATKATILIM PosIntegrator = "ZIRAATKATILIM" PosIntegrator_KUVEYTTURK PosIntegrator = "KUVEYTTURK" PosIntegrator_HALKBANK PosIntegrator = "HALKBANK" PosIntegrator_DENIZBANK PosIntegrator = "DENIZBANK" PosIntegrator_VAKIFBANK PosIntegrator = "VAKIFBANK" + PosIntegrator_VAKIFKATILIM PosIntegrator = "VAKIFKATILIM" PosIntegrator_FINANSBANK PosIntegrator = "FINANSBANK" - PosIntegrator_FINANSBANK_ASSECO PosIntegrator = "FINANSBANK_ASSECO" PosIntegrator_FIBABANK PosIntegrator = "FIBABANK" PosIntegrator_FIBABANK_ASSECO PosIntegrator = "FIBABANK_ASSECO" PosIntegrator_ANADOLUBANK PosIntegrator = "ANADOLUBANK" @@ -416,7 +419,11 @@ const ( PosIntegrator_OZAN PosIntegrator = "OZAN" PosIntegrator_BRAINTREE PosIntegrator = "BRAINTREE" PosIntegrator_NKOLAY PosIntegrator = "NKOLAY" - PosIntegrator_FAKE PosIntegrator = "FAKE" + PosIntegrator_PAYTABS PosIntegrator = "PAYTABS" + PosIntegrator_PAYBULL PosIntegrator = "PAYBULL" + PosIntegrator_ELEKSE PosIntegrator = "ELEKSE" + PosIntegrator_ALGORITMA PosIntegrator = "ALGORITMA" + PosIntegrator_PAYCELL PosIntegrator = "PAYCELL" ) const ( @@ -493,6 +500,23 @@ const ( BankAccountTrackingSource_YKB BankAccountTrackingSource = "YKB" ) +const ( + PaymentAuthenticationType_THREE_DS PaymentAuthenticationType = "THREE_DS" + PaymentAuthenticationType_NON_THREE_DS PaymentAuthenticationType = "NON_THREE_DS" +) + +const ( + CardBrand_BONUS CardBrand = "Bonus" + CardBrand_AXESS CardBrand = "Axess" + CardBrand_MAXIMUM CardBrand = "Maximum" + CardBrand_WORLD CardBrand = "World" + CardBrand_PARAF CardBrand = "Paraf" + CardBrand_CARD_FINANS CardBrand = "CardFinans" + CardBrand_BANKKART_COMBO CardBrand = "Bankkart Combo" + CardBrand_ADVANTAGE CardBrand = "Advantage" + CardBrand_SAGLAM_KART CardBrand = "Sağlam Kart" +) + // requests type CreatePaymentRequest struct { Price float64 `json:"price,omitempty"` @@ -1889,6 +1913,146 @@ type MasterpassCreatePayment struct { AdditionalParams map[string]interface{} `json:"additionalParams,omitempty"` } +type CreateMerchantRequest struct { + Name string `json:"name"` + LegalCompanyTitle string `json:"legalCompanyTitle"` + Email string `json:"email"` + SecretWord string `json:"secretWord,omitempty"` + Website string `json:"website"` + PhoneNumber string `json:"phoneNumber,omitempty"` + ContactName string `json:"contactName"` + ContactSurname string `json:"contactSurname"` + ContactPhoneNumber string `json:"contactPhoneNumber"` +} + +type MerchantApiCredential struct { + Name string `json:"name"` + ApiKey string `json:"apiKey"` + SecretKey string `json:"secretKey"` +} + +type CreateMerchantResponse struct { + Id *int64 `json:"id"` + Name *string `json:"name"` + MerchantApiCredentials []MerchantApiCredential `json:"merchantApiCredentials"` +} + +type CreateMerchantPosUser struct { + PosUsername string `json:"posUsername"` + PosPassword string `json:"posPassword"` + PosUserType PosUserType `json:"posUserType"` + PosOperationType PosOperationType `json:"posOperationType"` +} + +type CreateMerchantPosRequest struct { + Status PosStatus `json:"status"` + Name string `json:"name"` + ClientId string `json:"clientId"` + Currency Currency `json:"currency"` + PosnetId string `json:"posnetId,omitempty"` + TerminalId string `json:"terminalId,omitempty"` + ThreedsPosnetId string `json:"threedsPosnetId,omitempty"` + ThreedsTerminalId string `json:"threedsTerminalId,omitempty"` + ThreedsKey string `json:"threedsKey,omitempty"` + EnableForeignCard bool `json:"enableForeignCard"` + EnableInstallment bool `json:"enableInstallment"` + EnablePaymentWithoutCvc bool `json:"enablePaymentWithoutCvc"` + NewIntegration bool `json:"newIntegration"` + OrderNumber int64 `json:"orderNumber"` + PosIntegrator PosIntegrator `json:"posIntegrator"` + EnabledPaymentAuthenticationTypes []PaymentAuthenticationType `json:"enabledPaymentAuthenticationTypes"` + MerchantPosUsers []CreateMerchantPosUser `json:"merchantPosUsers"` +} + +type AutopilotState struct { + IsThreeDsUp bool `json:"isThreeDsUp"` + IsNonThreeDsUp bool `json:"isNonThreeDsUp"` +} + +type MerchantPosUser struct { + Id int64 `json:"id"` + PosUsername string `json:"posUsername"` + PosPassword string `json:"posPassword"` + PosUserType PosUserType `json:"posUserType"` + PosOperationType PosOperationType `json:"posOperationType"` +} +type MerchantPosResponse struct { + Id int64 `json:"id"` + Status PosStatus `json:"status"` + Name string `json:"name"` + Alias string `json:"alias"` + PosIntegrator PosIntegrator `json:"posIntegrator"` + Hostname string `json:"hostname"` + ClientId string `json:"clientId"` + PosCurrencyCode string `json:"posCurrencyCode"` + Mode string `json:"mode"` + Path string `json:"path"` + Port int64 `json:"port"` + PosnetId string `json:"posnetId"` + TerminalId string `json:"terminalId"` + ThreedsPosnetId string `json:"threedsPosnetId"` + ThreedsTerminalId string `json:"threedsTerminalId"` + ThreedsKey string `json:"threedsKey"` + ThreedsPath string `json:"threedsPath"` + EnableForeignCard bool `json:"enableForeignCard"` + EnableInstallment bool `json:"enableInstallment"` + EnablePaymentWithoutCvc bool `json:"enablePaymentWithoutCvc"` + NewIntegration bool `json:"newIntegration"` + OrderNumber int64 `json:"orderNumber"` + AutopilotState AutopilotState `json:"autopilotState"` + Currency Currency `json:"currency"` + BankId int64 `json:"bankId"` + BankName string `json:"bankName"` + IsPf bool `json:"isPf"` + MerchantPosUsers []MerchantPosUser `json:"merchantPosUsers"` + SupportedCardAssociations []CardAssociation `json:"supportedCardAssociations"` + EnabledPaymentAuthenticationTypes []PaymentAuthenticationType `json:"enabledPaymentAuthenticationTypes"` +} + +type MerchantPosCommissionResponse struct { + Id int64 `json:"id"` + Status Status `json:"status"` + Installment int64 `json:"installment"` + BlockageDay int64 `json:"blockageDay"` + InstallmentLabel string `json:"installmentLabel"` + CardBrandName CardBrand `json:"cardBrandName"` + BankOnUsCreditCardCommissionRate float64 `json:"bankOnUsCreditCardCommissionRate"` + BankNotOnUsCreditCardCommissionRate float64 `json:"bankNotOnUsCreditCardCommissionRate"` + BankOnUsDebitCardCommissionRate float64 `json:"bankOnUsDebitCardCommissionRate"` + BankNotOnUsDebitCardCommissionRate float64 `json:"bankNotOnUsDebitCardCommissionRate"` + BankForeignCardCommissionRate float64 `json:"bankForeignCardCommissionRate"` + MerchantCommissionRate float64 `json:"merchantCommissionRate"` +} + +type CreateMerchantPosCommission struct { + CardBrandName CardBrand `json:"cardBrandName,omitempty"` + Installment int64 `json:"installment"` + Status Status `json:"status"` + BlockageDay int64 `json:"blockageDay"` + InstallmentLabel string `json:"installmentLabel,omitempty"` + BankOnUsCreditCardCommissionRate float64 `json:"bankOnUsCreditCardCommissionRate"` + BankOnUsDebitCardCommissionRate float64 `json:"bankOnUsDebitCardCommissionRate,omitempty"` + BankNotOnUsCreditCardCommissionRate float64 `json:"bankNotOnUsCreditCardCommissionRate,omitempty"` + BankNotOnUsDebitCardCommissionRate float64 `json:"bankNotOnUsDebitCardCommissionRate,omitempty"` + BankForeignCardCommissionRate float64 `json:"bankForeignCardCommissionRate,omitempty"` + MerchantCommissionRate float64 `json:"merchantCommissionRate,omitempty"` +} + +type SearchMerchantPosRequest struct { + Name string `schema:"name,omitempty"` + Alias string `schema:"alias,omitempty"` + Currency Currency `schema:"currency,omitempty"` + EnableInstallment bool `schema:"enableInstallment,omitempty"` + EnableForeignCard bool `schema:"enableForeignCard,omitempty"` + BankName string `schema:"bankName,omitempty"` + Page int64 `schema:"page,omitempty"` + Size int64 `schema:"size,omitempty"` +} + +type CreateMerchantPosCommissionRequest struct { + Commissions []CreateMerchantPosCommission `json:"commissions"` +} + type PaymentError ErrorResponse type Void struct { diff --git a/adapter/onboarding.go b/adapter/onboarding.go index 51a8d73..39a1a3a 100644 --- a/adapter/onboarding.go +++ b/adapter/onboarding.go @@ -69,3 +69,18 @@ func (api *Onboarding) SearchMembers(ctx context.Context, request SearchMembersR return response.Data, nil } + +func (api *Onboarding) CreateMerchant(ctx context.Context, request CreateMerchantRequest) (*CreateMerchantResponse, error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/onboarding/v1/merchants", request) + + if err != nil { + return nil, err + } + + response := &Response[CreateMerchantResponse]{} + err = api.Client.Do(ctx, newRequest, response) + if err != nil { + return nil, err + } + return response.Data, nil +} diff --git a/tests/merchant_test.go b/tests/merchant_test.go new file mode 100644 index 0000000..534288e --- /dev/null +++ b/tests/merchant_test.go @@ -0,0 +1,128 @@ +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" + "testing" +) + +var merchantClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io") + +func Test_CreateMerchantPos(t *testing.T) { + request := adapter.CreateMerchantPosRequest{ + Name: "my test pos", + ClientId: "client id", + TerminalId: "terminal id", + ThreedsKey: "3d secure key", + Status: craftgate.PosStatus_AUTOPILOT, + Currency: craftgate.Currency_TRY, + OrderNumber: 1, + EnableInstallment: true, + EnableForeignCard: true, + EnablePaymentWithoutCvc: true, + PosIntegrator: craftgate.PosIntegrator_AKBANK, + EnabledPaymentAuthenticationTypes: []craftgate.PaymentAuthenticationType{ + craftgate.PaymentAuthenticationType_NON_THREE_DS, + craftgate.PaymentAuthenticationType_NON_THREE_DS, + }, + MerchantPosUsers: []craftgate.CreateMerchantPosUser{ + { + PosOperationType: craftgate.PosOperationType_STANDARD, + PosUserType: craftgate.PosUserType_API, + PosUsername: "username", + PosPassword: "password", + }, + }, + } + + res, err := merchantClient.Merchant.CreateMerchantPos(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} + +func Test_RetrieveMerchantPos(t *testing.T) { + res, err := merchantClient.Merchant.RetrieveMerchantPos(context.Background(), 1) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} + +func Test_UpdateMerchantPosStatus(t *testing.T) { + err := merchantClient.Merchant.UpdateMerchantPosStatus(context.Background(), 1, craftgate.PosStatus_ACTIVE) + + if err != nil { + t.Errorf("Error %s", err) + } +} + +func Test_DeleteMerchantPosStatus(t *testing.T) { + err := merchantClient.Merchant.DeleteMerchantPosStatus(context.Background(), 1) + + if err != nil { + t.Errorf("Error %s", err) + } +} + +func Test_RetrieveMerchantPosCommission(t *testing.T) { + res, err := merchantClient.Merchant.RetrieveMerchantPosCommissions(context.Background(), 14) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} + +func Test_UpdateMerchantPosCommissions(t *testing.T) { + req := adapter.CreateMerchantPosCommissionRequest{ + Commissions: []craftgate.CreateMerchantPosCommission{ + { + Installment: 1, + BlockageDay: 7, + Status: craftgate.Status_ACTIVE, + CardBrandName: craftgate.CardBrand_AXESS, + InstallmentLabel: "Single installment", + BankOnUsDebitCardCommissionRate: 1.0, + BankOnUsCreditCardCommissionRate: 1.1, + BankNotOnUsDebitCardCommissionRate: 1.2, + BankNotOnUsCreditCardCommissionRate: 1.3, + BankForeignCardCommissionRate: 1.5, + }, + { + Installment: 2, + BlockageDay: 7, + Status: craftgate.Status_ACTIVE, + CardBrandName: craftgate.CardBrand_AXESS, + InstallmentLabel: "installment 2", + BankOnUsCreditCardCommissionRate: 2.1, + MerchantCommissionRate: 2.3, + }, + }, + } + res, err := merchantClient.Merchant.UpdateMerchantPosCommissions(context.Background(), 14, req) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} + +func Test_SearchMerchantPos(t *testing.T) { + req := adapter.SearchMerchantPosRequest{ + Page: 0, + Size: 10, + Currency: adapter.Currency_TRY, + } + res, err := merchantClient.Merchant.SearchMerchantPos(context.Background(), req) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} diff --git a/tests/onboarding_test.go b/tests/onboarding_test.go index f684648..e1bde82 100644 --- a/tests/onboarding_test.go +++ b/tests/onboarding_test.go @@ -163,3 +163,22 @@ func Test_SearchMembers(t *testing.T) { t.Errorf("Error %s", err) } } + +func Test_CreateMerchant(t *testing.T) { + request := adapter.CreateMerchantRequest{ + Name: "newMerchant", + LegalCompanyTitle: "legalCompanyTitle", + Email: "new_merchant@merchant.com", + Website: "www.merchant.com", + ContactName: "newName", + ContactSurname: "newSurname", + ContactPhoneNumber: "905555555566", + } + + res, err := onboardingClient.Onboarding.CreateMerchant(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} From 2d1406774514d5a4449b80062c19b93928d6e9d5 Mon Sep 17 00:00:00 2001 From: Emre INAL <9061788+reywyn@users.noreply.github.com> Date: Thu, 7 Dec 2023 09:48:10 +0300 Subject: [PATCH 11/30] adds paymentStatus and additionalAction to initThreeDSPaymentResponse (#58) --- adapter/model.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adapter/model.go b/adapter/model.go index 96aca35..d4fbbcb 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -940,8 +940,10 @@ type PaymentTransactionResponse struct { } type Init3DSPaymentResponse struct { - HtmlContent *string `json:"htmlContent"` - PaymentId *int64 `json:"paymentId"` + HtmlContent *string `json:"htmlContent"` + PaymentId *int64 `json:"paymentId"` + PaymentStatus *PaymentStatus `json:"paymentStatus"` + AdditionalAction *AdditionalAction `json:"additionalAction"` } type InitCheckoutPaymentResponse struct { From 354a017425c02d61189be5b7b8e9f4ff3c15cf62 Mon Sep 17 00:00:00 2001 From: Onur Polattimur Date: Mon, 25 Dec 2023 10:08:09 +0300 Subject: [PATCH 12/30] Add loyalty support for masterpass payments (#61) --- adapter/model.go | 1 + 1 file changed, 1 insertion(+) diff --git a/adapter/model.go b/adapter/model.go index d4fbbcb..1fc949b 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -815,6 +815,7 @@ type MasterpassPaymentTokenGenerateRequest struct { BinNumber string `json:"binNumber,omitempty"` ForceThreeDS bool `json:"forceThreeDS,omitempty"` CreatePayment MasterpassCreatePayment `json:"createPayment,omitempty"` + Loyalty Loyalty `json:"loyalty,omitempty"` } type MasterpassPaymentCompleteRequest struct { From b5b5c8e52ce26052aa7fa78bccbca84845d10432 Mon Sep 17 00:00:00 2001 From: Beran Santur Date: Mon, 25 Dec 2023 16:22:34 +0300 Subject: [PATCH 13/30] QNB_PAY and TAMI pos integrators are added (#60) --- adapter/model.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adapter/model.go b/adapter/model.go index 1fc949b..47b1e75 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -424,6 +424,8 @@ const ( PosIntegrator_ELEKSE PosIntegrator = "ELEKSE" PosIntegrator_ALGORITMA PosIntegrator = "ALGORITMA" PosIntegrator_PAYCELL PosIntegrator = "PAYCELL" + PosIntegrator_TAMI PosIntegrator = "TAMI" + PosIntegrator_QNB_PAY PosIntegrator = "QNB_PAY" ) const ( From 675224526cd27114e79cb1da057a8532ec29bfe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alican=20Akku=C5=9F?= Date: Tue, 2 Jan 2024 17:17:01 +0300 Subject: [PATCH 14/30] adds localization (#64) --- README.md | 17 +++++++++++++++++ adapter/craftgate.go | 15 ++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e20bb8c..d4e8fa2 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,23 @@ if err != nil { } ``` +Also, you can pass the options to make localization for API responses. You can use `tr` or `en` right now. +```go +client, _ := craftgate.New("", "", "https://api.craftgate.io", craftgate.WithLocalization("en")) + +request := craftgate.SearchInstallmentsRequest{ + BinNumber: "487074", + Price: 100, + Currency: craftgate.Currency_TRY, +} + +res, err := client.Installment.SearchInstallments(context.Background(), request) + +if err != nil { + t.Errorf("Error %s", err) +} +``` + You should use production API servers at `https://api.craftgate.io` for real world. For testing purposes, please use the sandbox URL `https://sandbox-api.craftgate.io`. ## Examples diff --git a/adapter/craftgate.go b/adapter/craftgate.go index 06a5fb4..533cc18 100644 --- a/adapter/craftgate.go +++ b/adapter/craftgate.go @@ -65,6 +65,17 @@ func init() { type ClientOption func(*Client) error +func WithLocalization(lang string) ClientOption { + return func(client *Client) error { + if len(lang) > 0 { + client.headers["lang"] = strings.ToLower(lang) + } else { + client.headers["lang"] = "tr" + } + return nil + } +} + type Client struct { httpClient *http.Client baseURL *url.URL @@ -90,6 +101,8 @@ type Client struct { func New(apiKey, apiSecret, baseURL string, opts ...ClientOption) (*Client, error) { client := newClient(apiKey, apiSecret) + client.headers = make(map[string]string) + for _, option := range opts { if err := option(client); err != nil { return nil, err @@ -102,7 +115,7 @@ func New(apiKey, apiSecret, baseURL string, opts ...ClientOption) (*Client, erro if client.baseURL == nil { client.baseURL, _ = url.Parse(baseURL) } - client.headers = make(map[string]string) + return client, nil } From c24ac30852e64bfedf4b01300da92b36821677bd Mon Sep 17 00:00:00 2001 From: Yusuf ATALAY Date: Fri, 5 Jan 2024 10:16:31 +0300 Subject: [PATCH 15/30] Adds new ClientOption function (#65) --- adapter/craftgate.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/adapter/craftgate.go b/adapter/craftgate.go index 533cc18..b4311f3 100644 --- a/adapter/craftgate.go +++ b/adapter/craftgate.go @@ -76,6 +76,17 @@ func WithLocalization(lang string) ClientOption { } } +func WithCustomHTTPClient(httpClient *http.Client) ClientOption { + return func(client *Client) error { + if httpClient != nil { + client.httpClient = httpClient + } else { + client.httpClient = http.DefaultClient + } + return nil + } +} + type Client struct { httpClient *http.Client baseURL *url.URL From 45ac5814c963f53fe844210ec3fbd9498ea3589f Mon Sep 17 00:00:00 2001 From: Serhat Tunca <35580464+tuncaserhat@users.noreply.github.com> Date: Mon, 8 Jan 2024 15:12:03 +0300 Subject: [PATCH 16/30] change fraud list management (#63) --- adapter/fraud.go | 7 ++++--- adapter/model.go | 35 ++++++++++++++++++++++++----------- tests/fraud_test.go | 38 +++++++++++++++++++++++++++++++++++--- 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/adapter/fraud.go b/adapter/fraud.go index 7a3efc9..28bfce6 100644 --- a/adapter/fraud.go +++ b/adapter/fraud.go @@ -54,9 +54,10 @@ func (api *Fraud) RetrieveFraudValueList(ctx context.Context, listName string) ( return response.Data, nil } -func (api *Fraud) CreateFraudValueList(ctx context.Context, listName string) error { +func (api *Fraud) CreateFraudValueList(ctx context.Context, listName string, fraudValueType FraudValueType) error { request := FraudValueListRequest{ ListName: listName, + Type: fraudValueType, } newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/fraud/v1/value-lists", request) @@ -103,8 +104,8 @@ func (api *Fraud) AddValueToFraudValueList(ctx context.Context, request FraudVal return nil } -func (api *Fraud) RemoveValueFromFraudValueList(ctx context.Context, listName, value string) error { - newRequest, err := api.Client.NewRequest(ctx, http.MethodDelete, "/fraud/v1/value-lists/"+listName+"/values/"+value, nil) +func (api *Fraud) RemoveValueFromFraudValueList(ctx context.Context, listName, valueId string) error { + newRequest, err := api.Client.NewRequest(ctx, http.MethodDelete, "/fraud/v1/value-lists/"+listName+"/values/"+valueId, nil) if err != nil { return err } diff --git a/adapter/model.go b/adapter/model.go index 47b1e75..a9413a3 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -31,6 +31,7 @@ type TransactionPayoutStatus string type WalletTransactionRefundTransactionType string type FraudAction string type FraudCheckStatus string +type FraudValueType string type AdditionalAction string type ApmAdditionalAction string type ReportFileType string @@ -325,6 +326,15 @@ const ( FraudCheckStatus_FRAUD FraudCheckStatus = "FRAUD" ) +// fraud value type type declaration +const ( + FraudValueType_CARD FraudValueType = "CARD" + FraudValueType_IP FraudValueType = "IP" + FraudValueType_PHONE_NUMBER FraudValueType = "PHONE_NUMBER" + FraudValueType_EMAIL FraudValueType = "EMAIL" + FraudValueType_OTHER FraudValueType = "OTHER" +) + // apm additional action type declaration const ( ApmAdditionalAction_REDIRECT_TO_URL ApmAdditionalAction = "REDIRECT_TO_URL" @@ -1747,20 +1757,21 @@ type FraudCheckResponse struct { } type FraudPaymentData struct { - PaymentDate *time.Time `json:"paymentDate"` - ConversationId *string `json:"conversationId"` - PaidPrice *float64 `json:"paidPrice"` - Currency *Currency `json:"currency"` - CardFingerprintId *string `json:"cardFingerprintId"` - CardFingerprintExpirationDate *time.Time `json:"cardFingerprintExpirationDate"` - BuyerId *int64 `json:"buyerId"` - ClientIp *string `json:"clientIp"` + PaymentDate *time.Time `json:"paymentDate"` + ConversationId *string `json:"conversationId"` + PaidPrice *float64 `json:"paidPrice"` + Currency *Currency `json:"currency"` + BuyerId *int64 `json:"buyerId"` + ClientIp *string `json:"clientIp"` } type FraudValueListRequest struct { - ListName string `json:"listName,omitempty"` - Value string `json:"value,omitempty"` - DurationInSeconds int `json:"durationInSeconds,omitempty"` + ListName string `json:"listName,omitempty"` + Type FraudValueType `json:"type,omitempty"` + Label string `json:"label,omitempty"` + Value string `json:"value,omitempty"` + PaymentId int64 `json:"paymentId"` + DurationInSeconds int `json:"durationInSeconds,omitempty"` } type FraudValuesResponse struct { @@ -1769,6 +1780,8 @@ type FraudValuesResponse struct { } type FraudValue struct { + Id *string `json:"id"` + Label *string `json:"label"` Value *string `json:"value"` ExpireInSeconds *int `json:"expireInSeconds"` } diff --git a/tests/fraud_test.go b/tests/fraud_test.go index 86e6b25..8f62811 100644 --- a/tests/fraud_test.go +++ b/tests/fraud_test.go @@ -42,7 +42,7 @@ func Test_RetrieveFraudValueList(t *testing.T) { } func Test_CreateFraudValueList(t *testing.T) { - err := fraudClient.Fraud.CreateFraudValueList(context.Background(), "myTestList") + err := fraudClient.Fraud.CreateFraudValueList(context.Background(), "ipList", craftgate.FraudValueType_IP) if err != nil { t.Errorf("Error %s", err) @@ -60,7 +60,39 @@ func Test_DeleteFraudValueList(t *testing.T) { func Test_AddValueToFraudValueList(t *testing.T) { request := adapter.FraudValueListRequest{ ListName: "ipList", - Value: "999.999.999.999", + Type: craftgate.FraudValueType_IP, + Label: "local ip 1", + Value: "127.0.0.1", + } + err := fraudClient.Fraud.AddValueToFraudValueList(context.Background(), request) + + if err != nil { + t.Errorf("Error %s", err) + } +} + +func Test_AddTemporaryValueToFraudValueList(t *testing.T) { + request := adapter.FraudValueListRequest{ + ListName: "ipList", + Type: craftgate.FraudValueType_IP, + Label: "local ip 2", + Value: "127.0.0.2", + DurationInSeconds: 60, + } + + err := fraudClient.Fraud.AddValueToFraudValueList(context.Background(), request) + + if err != nil { + t.Errorf("Error %s", err) + } +} + +func Test_AddCardFingerprintToFraudValueList(t *testing.T) { + request := adapter.FraudValueListRequest{ + ListName: "cardList", + Type: craftgate.FraudValueType_CARD, + Label: "John Doe's Card", + PaymentId: 11675, } err := fraudClient.Fraud.AddValueToFraudValueList(context.Background(), request) @@ -70,7 +102,7 @@ func Test_AddValueToFraudValueList(t *testing.T) { } func Test_RemoveValueFromFraudValueList(t *testing.T) { - err := fraudClient.Fraud.RemoveValueFromFraudValueList(context.Background(), "ipList", "999.999.999.999") + err := fraudClient.Fraud.RemoveValueFromFraudValueList(context.Background(), "ipList", "7aac0ad8-d170-4c2b-89d3-440fcf145b35") if err != nil { t.Errorf("Error %s", err) From afa31500319e5333fb15075f9faa0edd000b2d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Derya=20=C3=87akmak?= <36774966+deryacakmak@users.noreply.github.com> Date: Mon, 8 Jan 2024 15:13:36 +0300 Subject: [PATCH 17/30] Akbank and Tap Integration (#62) --- adapter/model.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/adapter/model.go b/adapter/model.go index a9413a3..868297b 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -151,6 +151,11 @@ const ( Currency_IQD Currency = "IQD" Currency_AZN Currency = "AZN" Currency_KZT Currency = "KZT" + Currency_KWD Currency = "KWD" + Currency_SAR Currency = "SAR" + Currency_BHD Currency = "BHD" + Currency_RUB Currency = "RUB" + Currency_JPY Currency = "JPY" ) // payment group declaration @@ -436,6 +441,8 @@ const ( PosIntegrator_PAYCELL PosIntegrator = "PAYCELL" PosIntegrator_TAMI PosIntegrator = "TAMI" PosIntegrator_QNB_PAY PosIntegrator = "QNB_PAY" + PosIntegrator_AKBANK_VPOS PosIntegrator = "AKBANK_VPOS" + PosIntegrator_TAP PosIntegrator = "TAP" ) const ( From 69021769c57f86edaacbdfb857e3b3659ca6a420 Mon Sep 17 00:00:00 2001 From: Beran Santur Date: Tue, 23 Jan 2024 16:20:18 +0300 Subject: [PATCH 18/30] Bnpl CartItem type change (#66) --- adapter/model.go | 2 ++ tests/payment_test.go | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/adapter/model.go b/adapter/model.go index 868297b..0a9ce9d 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -484,6 +484,8 @@ const ( const ( BnplCartItemType_MOBILE_PHONE_OVER_5000_TRY BnplCartItemType = "MOBILE_PHONE_OVER_5000_TRY" BnplCartItemType_MOBILE_PHONE_BELOW_5000_TRY BnplCartItemType = "MOBILE_PHONE_BELOW_5000_TRY" + BnplCartItemType_MOBILE_PHONE_PRICE_ABOVE_REGULATION_LIMIT BnplCartItemType = "MOBILE_PHONE_PRICE_ABOVE_REGULATION_LIMIT" + BnplCartItemType_MOBILE_PHONE_PRICE_BELOW_REGULATION_LIMIT BnplCartItemType = "MOBILE_PHONE_PRICE_BELOW_REGULATION_LIMIT" BnplCartItemType_TABLET BnplCartItemType = "TABLET" BnplCartItemType_COMPUTER BnplCartItemType = "COMPUTER" BnplCartItemType_CONSTRUCTION_MARKET BnplCartItemType = "CONSTRUCTION_MARKET" diff --git a/tests/payment_test.go b/tests/payment_test.go index fe0544a..881d4f5 100644 --- a/tests/payment_test.go +++ b/tests/payment_test.go @@ -781,7 +781,7 @@ func TestPayment_BnplPaymentOffer(t *testing.T) { Id: "200", Name: "Test Elektronik 2", BrandName: "iphone", - Type: craftgate.BnplCartItemType_MOBILE_PHONE_BELOW_5000_TRY, + Type: craftgate.BnplCartItemType_MOBILE_PHONE_PRICE_BELOW_REGULATION_LIMIT, UnitPrice: 3000, Quantity: 2, }, @@ -841,7 +841,7 @@ func TestPayment_InitBnplPayment(t *testing.T) { Id: "100", Name: "Test Elektronik 1", BrandName: "Samsung", - Type: craftgate.BnplCartItemType_MOBILE_PHONE_OVER_5000_TRY, + Type: craftgate.BnplCartItemType_MOBILE_PHONE_PRICE_ABOVE_REGULATION_LIMIT, UnitPrice: 4000, Quantity: 1, }, From 8a584a1e1344a696a2ab5428a48145f9041b1309 Mon Sep 17 00:00:00 2001 From: Serhat Tunca <35580464+tuncaserhat@users.noreply.github.com> Date: Tue, 30 Jan 2024 10:07:16 +0300 Subject: [PATCH 19/30] add rubik pos integrator (#68) --- adapter/model.go | 53 ++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/adapter/model.go b/adapter/model.go index 0a9ce9d..69098da 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -443,6 +443,7 @@ const ( PosIntegrator_QNB_PAY PosIntegrator = "QNB_PAY" PosIntegrator_AKBANK_VPOS PosIntegrator = "AKBANK_VPOS" PosIntegrator_TAP PosIntegrator = "TAP" + PosIntegrator_RUBIK PosIntegrator = "RUBIK" ) const ( @@ -482,32 +483,32 @@ const ( // BnplCartItemType type declaration const ( - BnplCartItemType_MOBILE_PHONE_OVER_5000_TRY BnplCartItemType = "MOBILE_PHONE_OVER_5000_TRY" - BnplCartItemType_MOBILE_PHONE_BELOW_5000_TRY BnplCartItemType = "MOBILE_PHONE_BELOW_5000_TRY" - BnplCartItemType_MOBILE_PHONE_PRICE_ABOVE_REGULATION_LIMIT BnplCartItemType = "MOBILE_PHONE_PRICE_ABOVE_REGULATION_LIMIT" - BnplCartItemType_MOBILE_PHONE_PRICE_BELOW_REGULATION_LIMIT BnplCartItemType = "MOBILE_PHONE_PRICE_BELOW_REGULATION_LIMIT" - BnplCartItemType_TABLET BnplCartItemType = "TABLET" - BnplCartItemType_COMPUTER BnplCartItemType = "COMPUTER" - BnplCartItemType_CONSTRUCTION_MARKET BnplCartItemType = "CONSTRUCTION_MARKET" - BnplCartItemType_GOLD BnplCartItemType = "GOLD" - BnplCartItemType_DIGITAL_PRODUCTS BnplCartItemType = "DIGITAL_PRODUCTS" - BnplCartItemType_SUPERMARKET BnplCartItemType = "SUPERMARKET" - BnplCartItemType_WHITE_GOODS BnplCartItemType = "WHITE_GOODS" - BnplCartItemType_WEARABLE_TECHNOLOGY BnplCartItemType = "WEARABLE_TECHNOLOGY" - BnplCartItemType_SMALL_HOME_APPLIANCES BnplCartItemType = "SMALL_HOME_APPLIANCES" - BnplCartItemType_TV BnplCartItemType = "TV" - BnplCartItemType_GAMES_CONSOLES BnplCartItemType = "GAMES_CONSOLES" - BnplCartItemType_AIR_CONDITIONER_AND_HEATER BnplCartItemType = "AIR_CONDITIONER_AND_HEATER" - BnplCartItemType_ELECTRONICS BnplCartItemType = "ELECTRONICS" - BnplCartItemType_ACCESSORIES BnplCartItemType = "ACCESSORIES" - BnplCartItemType_MOM_AND_BABY_AND_KIDS BnplCartItemType = "MOM_AND_BABY_AND_KIDS" - BnplCartItemType_SHOES BnplCartItemType = "SHOES" - BnplCartItemType_CLOTHING BnplCartItemType = "CLOTHING" - BnplCartItemType_COSMETICS_AND_PERSONAL_CARE BnplCartItemType = "COSMETICS_AND_PERSONAL_CARE" - BnplCartItemType_FURNITURE BnplCartItemType = "FURNITURE" - BnplCartItemType_HOME_LIVING BnplCartItemType = "HOME_LIVING" - BnplCartItemType_AUTOMOBILE_MOTORCYCLE BnplCartItemType = "AUTOMOBILE_MOTORCYCLE" - BnplCartItemType_OTHER BnplCartItemType = "OTHER" + BnplCartItemType_MOBILE_PHONE_OVER_5000_TRY BnplCartItemType = "MOBILE_PHONE_OVER_5000_TRY" + BnplCartItemType_MOBILE_PHONE_BELOW_5000_TRY BnplCartItemType = "MOBILE_PHONE_BELOW_5000_TRY" + BnplCartItemType_MOBILE_PHONE_PRICE_ABOVE_REGULATION_LIMIT BnplCartItemType = "MOBILE_PHONE_PRICE_ABOVE_REGULATION_LIMIT" + BnplCartItemType_MOBILE_PHONE_PRICE_BELOW_REGULATION_LIMIT BnplCartItemType = "MOBILE_PHONE_PRICE_BELOW_REGULATION_LIMIT" + BnplCartItemType_TABLET BnplCartItemType = "TABLET" + BnplCartItemType_COMPUTER BnplCartItemType = "COMPUTER" + BnplCartItemType_CONSTRUCTION_MARKET BnplCartItemType = "CONSTRUCTION_MARKET" + BnplCartItemType_GOLD BnplCartItemType = "GOLD" + BnplCartItemType_DIGITAL_PRODUCTS BnplCartItemType = "DIGITAL_PRODUCTS" + BnplCartItemType_SUPERMARKET BnplCartItemType = "SUPERMARKET" + BnplCartItemType_WHITE_GOODS BnplCartItemType = "WHITE_GOODS" + BnplCartItemType_WEARABLE_TECHNOLOGY BnplCartItemType = "WEARABLE_TECHNOLOGY" + BnplCartItemType_SMALL_HOME_APPLIANCES BnplCartItemType = "SMALL_HOME_APPLIANCES" + BnplCartItemType_TV BnplCartItemType = "TV" + BnplCartItemType_GAMES_CONSOLES BnplCartItemType = "GAMES_CONSOLES" + BnplCartItemType_AIR_CONDITIONER_AND_HEATER BnplCartItemType = "AIR_CONDITIONER_AND_HEATER" + BnplCartItemType_ELECTRONICS BnplCartItemType = "ELECTRONICS" + BnplCartItemType_ACCESSORIES BnplCartItemType = "ACCESSORIES" + BnplCartItemType_MOM_AND_BABY_AND_KIDS BnplCartItemType = "MOM_AND_BABY_AND_KIDS" + BnplCartItemType_SHOES BnplCartItemType = "SHOES" + BnplCartItemType_CLOTHING BnplCartItemType = "CLOTHING" + BnplCartItemType_COSMETICS_AND_PERSONAL_CARE BnplCartItemType = "COSMETICS_AND_PERSONAL_CARE" + BnplCartItemType_FURNITURE BnplCartItemType = "FURNITURE" + BnplCartItemType_HOME_LIVING BnplCartItemType = "HOME_LIVING" + BnplCartItemType_AUTOMOBILE_MOTORCYCLE BnplCartItemType = "AUTOMOBILE_MOTORCYCLE" + BnplCartItemType_OTHER BnplCartItemType = "OTHER" ) // RecordType declaration From 84104aad60d537894b15136086fa1b156fb7f162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alican=20Akku=C5=9F?= Date: Fri, 9 Feb 2024 11:42:56 +0300 Subject: [PATCH 20/30] adds haso bnpl (#67) --- adapter/model.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adapter/model.go b/adapter/model.go index 69098da..4a16b9b 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -87,6 +87,7 @@ const ( ApmType_ALFABANK ApmType = "ALFABANK" ApmType_TOM_FINANCE ApmType = "TOM_FINANCE" ApmType_STRIPE ApmType = "STRIPE" + ApmType_HASO ApmType = "HASO" ApmType_FUND_TRANSFER ApmType = "FUND_TRANSFER" ApmType_CASH_ON_DELIVERY ApmType = "CASH_ON_DELIVERY" ) @@ -112,6 +113,7 @@ const ( PaymentProvider_GOOGLEPAY PaymentProvider = "GOOGLEPAY" PaymentProvider_HEPSIPAY PaymentProvider = "HEPSIPAY" PaymentProvider_STRIPE PaymentProvider = "STRIPE" + PaymentProvider_HASO PaymentProvider = "HASO" PaymentProvider_OFFLINE PaymentProvider = "OFFLINE" ) From 19a65f617597873e3e01f206a67df89f944e2494 Mon Sep 17 00:00:00 2001 From: Beran Santur Date: Tue, 13 Feb 2024 16:39:15 +0300 Subject: [PATCH 21/30] Adds Juzdan integration to Go Client (#69) * Adds Juzdan integration to Go CLient * Adds Juzdan integration to Go CLient * Adds Juzdan integration to Go CLient * Adds Juzdan integration to Go Client * Adds Juzdan integration to Go Client * Adds Juzdan integration to Go Client * fix --- adapter/craftgate.go | 1 + adapter/juzdan.go | 41 +++++++++++++++++++++++++++++++ adapter/model.go | 28 +++++++++++++++++++++ tests/juzdan_test.go | 58 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 adapter/juzdan.go create mode 100644 tests/juzdan_test.go diff --git a/adapter/craftgate.go b/adapter/craftgate.go index b4311f3..b181a4a 100644 --- a/adapter/craftgate.go +++ b/adapter/craftgate.go @@ -108,6 +108,7 @@ type Client struct { Masterpass *Masterpass BankAccountTracking *BankAccountTracking Merchant *Merchant + Juzdan *Juzdan } func New(apiKey, apiSecret, baseURL string, opts ...ClientOption) (*Client, error) { diff --git a/adapter/juzdan.go b/adapter/juzdan.go new file mode 100644 index 0000000..dc4c178 --- /dev/null +++ b/adapter/juzdan.go @@ -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("/payment/v1/juzdan-payments/%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 +} diff --git a/adapter/model.go b/adapter/model.go index 4a16b9b..1ee758f 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -50,6 +50,7 @@ type BankAccountTrackingSource string type BnplCartItemType string type PaymentAuthenticationType string type CardBrand string +type ClientType string const ( ApiKeyHeaderName = "x-api-key" @@ -541,6 +542,11 @@ const ( CardBrand_SAGLAM_KART CardBrand = "Sağlam Kart" ) +const ( + ClientType_W ClientType = "W" + ClientType_M ClientType = "M" +) + // requests type CreatePaymentRequest struct { Price float64 `json:"price,omitempty"` @@ -2083,6 +2089,28 @@ type CreateMerchantPosCommissionRequest struct { Commissions []CreateMerchantPosCommission `json:"commissions"` } +type InitJuzdanPaymentRequest struct { + Price float64 `json:"price,omitempty"` + PaidPrice float64 `json:"paidPrice,omitempty"` + Currency Currency `json:"currency,omitempty"` + PaymentGroup PaymentGroup `json:"paymentGroup,omitempty"` + ConversationId string `json:"conversationId,omitempty"` + ExternalId string `json:"externalId,omitempty"` + CallbackUrl string `json:"callbackUrl,omitempty"` + PaymentPhase PaymentPhase `json:"paymentPhase,omitempty"` + PaymentChannel string `json:"paymentChannel,omitempty"` + BuyerMemberId int64 `json:"buyerMemberId,omitempty"` + BankOrderId string `json:"bankOrderId,omitempty"` + Items []PaymentItem `json:"items"` + ClientType ClientType `json:"clientType,omitempty"` + LoanCampaignId int64 `json:"loanCampaignId,omitempty"` +} + +type InitJuzdanPaymentResponse struct { + ReferenceId string `json:"referenceId"` + JuzdanQrUrl string `json:"juzdanQrUrl"` +} + type PaymentError ErrorResponse type Void struct { diff --git a/tests/juzdan_test.go b/tests/juzdan_test.go new file mode 100644 index 0000000..b9eea22 --- /dev/null +++ b/tests/juzdan_test.go @@ -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" + "github.com/davecgh/go-spew/spew" + "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", + 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) + } +} From 20d16516f0e318f8f1cea1d38ed1548381a27f96 Mon Sep 17 00:00:00 2001 From: Beran Santur Date: Mon, 19 Feb 2024 16:10:40 +0300 Subject: [PATCH 22/30] Fixed test error (#72) --- main_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index 88fe110..dd41479 100644 --- a/main_test.go +++ b/main_test.go @@ -25,7 +25,7 @@ func Test_main(t *testing.T) { binNumber, err := client.Installment.RetrieveBinNumber(context.Background(), "487074") require.NotNil(t, err) require.Nil(t, binNumber) - assert.Equal(t, true, strings.Contains(err.Error(), "API credential not found!")) + assert.Equal(t, true, strings.Contains(err.Error(), "API credential not found")) }) }) } From 8c3649bb96157de303610516285c44b2630fd945 Mon Sep 17 00:00:00 2001 From: Emre INAL <9061788+reywyn@users.noreply.github.com> Date: Mon, 19 Feb 2024 16:30:01 +0300 Subject: [PATCH 23/30] Update github build action (#73) --- .github/workflows/go.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 9d05c36..1f37b8e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -7,20 +7,18 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - - name: Set up Go 1.19 - uses: actions/setup-go@v3 + - name: Set up Go + uses: actions/setup-go@v5 with: - go-version-file: go.mod + go-version: '1.21.0' cache: true cache-dependency-path: go.sum - name: Check out code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Go Lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v4 - name: Get dependencies run: | From cf1f940fba9d922214bd91116f8cfe7bfafed61f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Derya=20=C3=87akmak?= <36774966+deryacakmak@users.noreply.github.com> Date: Tue, 19 Mar 2024 17:37:24 +0300 Subject: [PATCH 24/30] Garanti Bank account tracking (#70) * Garanti Bank account tracking * fix test --------- Co-authored-by: Lemi Orhan Ergin --- adapter/model.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adapter/model.go b/adapter/model.go index 1ee758f..24decf2 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -522,7 +522,8 @@ const ( // BankAccountTrackingSource declaration const ( - BankAccountTrackingSource_YKB BankAccountTrackingSource = "YKB" + BankAccountTrackingSource_YKB BankAccountTrackingSource = "YKB" + BankAccountTrackingSource_GARANTI BankAccountTrackingSource = "GARANTI" ) const ( From bfd8397c32b9418be3ec7408abd39775d66a71e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alican=20Akku=C5=9F?= Date: Wed, 20 Mar 2024 11:20:11 +0300 Subject: [PATCH 25/30] Add loyalty exists while searching installment (#77) --- adapter/model.go | 1 + 1 file changed, 1 insertion(+) diff --git a/adapter/model.go b/adapter/model.go index 24decf2..e902c03 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -1298,6 +1298,7 @@ type SearchInstallmentsRequest struct { Price float64 `schema:"price"` Currency Currency `schema:"currency"` DistinctCardBrandsWithLowestCommissions bool `schema:"distinctCardBrandsWithLowestCommissions"` + LoyaltyExists bool `schema:"loyaltyExists"` } type InstallmentListResponse struct { From 7a45097a4ae98c6b642991143f0c591bed0cbd80 Mon Sep 17 00:00:00 2001 From: Beran Santur Date: Wed, 20 Mar 2024 13:44:01 +0300 Subject: [PATCH 26/30] Add version of search payout completed tx with pagination (#76) * Add version of search payout completed tx with pagination * Add version of search payout completed tx with pagination * Add version of search payout completed tx with pagination --- adapter/model.go | 2 ++ adapter/settlement_reporting.go | 2 +- tests/settlement_reporting_test.go | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/adapter/model.go b/adapter/model.go index e902c03..d16fad7 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -1680,6 +1680,8 @@ type SearchPayoutCompletedTransactionsRequest struct { SettlementType SettlementType `schema:"settlementType,omitempty"` StartDate time.Time `schema:"startDate,omitempty"` EndDate time.Time `schema:"endDate,omitempty"` + Page int `schema:"page"` + Size int `schema:"size"` } type SearchPayoutBouncedTransactionsRequest struct { diff --git a/adapter/settlement_reporting.go b/adapter/settlement_reporting.go index 14b270c..5218f29 100644 --- a/adapter/settlement_reporting.go +++ b/adapter/settlement_reporting.go @@ -11,7 +11,7 @@ type SettlementReporting struct { } func (api *SettlementReporting) SearchPayoutCompletedTransactions(ctx context.Context, request SearchPayoutCompletedTransactionsRequest) (*DataResponse[SearchPayoutCompletedTransactionsResponse], error) { - newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, "/settlement-reporting/v1/settlement-file/payout-completed-transactions", request) + newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, "/settlement-reporting/v2/settlement-file/payout-completed-transactions", request) if err != nil { return nil, err } diff --git a/tests/settlement_reporting_test.go b/tests/settlement_reporting_test.go index d477e32..ef651fd 100644 --- a/tests/settlement_reporting_test.go +++ b/tests/settlement_reporting_test.go @@ -15,6 +15,8 @@ func TestSettlementReporting_SearchPayoutCompletedTransactions(t *testing.T) { request := adapter.SearchPayoutCompletedTransactionsRequest{ StartDate: time.Now().AddDate(0, 0, -180), EndDate: time.Now(), + Page: 0, + Size: 10, } res, err := settlementReportingClient.SettlementReporting.SearchPayoutCompletedTransactions(context.Background(), request) From ea59525c9c4265567e827cfd211939e37bf4e095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alican=20Akku=C5=9F?= Date: Wed, 20 Mar 2024 14:50:45 +0300 Subject: [PATCH 27/30] adds paycell as a new apm and provider type (#59) --- adapter/model.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/adapter/model.go b/adapter/model.go index d16fad7..9a2966f 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -88,6 +88,7 @@ const ( ApmType_ALFABANK ApmType = "ALFABANK" ApmType_TOM_FINANCE ApmType = "TOM_FINANCE" ApmType_STRIPE ApmType = "STRIPE" + ApmType_PAYCELL ApmType = "PAYCELL" ApmType_HASO ApmType = "HASO" ApmType_FUND_TRANSFER ApmType = "FUND_TRANSFER" ApmType_CASH_ON_DELIVERY ApmType = "CASH_ON_DELIVERY" @@ -108,12 +109,16 @@ const ( PaymentProvider_PAYPAL PaymentProvider = "PAYPAL" PaymentProvider_KLARNA PaymentProvider = "KLARNA" PaymentProvider_AFTERPAY PaymentProvider = "AFTERPAY" - PaymentProvider_KASPI PaymentProvider = "KASPI" - PaymentProvider_TOMPAY PaymentProvider = "TOMPAY" PaymentProvider_APPLEPAY PaymentProvider = "APPLEPAY" PaymentProvider_GOOGLEPAY PaymentProvider = "GOOGLEPAY" PaymentProvider_HEPSIPAY PaymentProvider = "HEPSIPAY" PaymentProvider_STRIPE PaymentProvider = "STRIPE" + PaymentProvider_KASPI PaymentProvider = "KASPI" + PaymentProvider_MASLAK PaymentProvider = "MASLAK" + PaymentProvider_TOMPAY PaymentProvider = "TOMPAY" + PaymentProvider_TOM_FINANCE PaymentProvider = "TOM_FINANCE" + PaymentProvider_ALFABANK PaymentProvider = "ALFABANK" + PaymentProvider_PAYCELL PaymentProvider = "PAYCELL" PaymentProvider_HASO PaymentProvider = "HASO" PaymentProvider_OFFLINE PaymentProvider = "OFFLINE" ) From 5226ed333413e8680ebee5a3f94a3432f53b7309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Semih=20=C5=9Eahan?= Date: Thu, 21 Mar 2024 16:11:29 +0300 Subject: [PATCH 28/30] Adds instant transfer with Compay integration as apm (#78) * Adds instant transfer with Compay integration as apm * Update * Update * Update --- adapter/model.go | 97 +++++++++++++++----------- adapter/payment.go | 14 ++++ tests/instant_transfer_payment_test.go | 53 ++++++++++++++ 3 files changed, 123 insertions(+), 41 deletions(-) create mode 100644 tests/instant_transfer_payment_test.go diff --git a/adapter/model.go b/adapter/model.go index 9a2966f..e010520 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -83,6 +83,7 @@ const ( ApmType_KLARNA ApmType = "KLARNA" ApmType_AFTERPAY ApmType = "AFTERPAY" ApmType_KASPI ApmType = "KASPI" + ApmType_INSTANT_TRANSFER ApmType = "INSTANT_TRANSFER" ApmType_TOMPAY ApmType = "TOMPAY" ApmType_MASLAK ApmType = "MASLAK" ApmType_ALFABANK ApmType = "ALFABANK" @@ -96,31 +97,32 @@ const ( // payment provider declaration const ( - PaymentProvider_BANK PaymentProvider = "BANK" - PaymentProvider_CG_WALLET PaymentProvider = "CG_WALLET" - PaymentProvider_MASTERPASS PaymentProvider = "MASTERPASS" - PaymentProvider_GARANTI_PAY PaymentProvider = "GARANTI_PAY" - PaymentProvider_YKB_WORLD_PAY PaymentProvider = "YKB_WORLD_PAY" - PaymentProvider_PAPARA PaymentProvider = "PAPARA" - PaymentProvider_PAYONEER PaymentProvider = "PAYONEER" - PaymentProvider_SODEXO PaymentProvider = "SODEXO" - PaymentProvider_EDENRED PaymentProvider = "EDENRED" - PaymentProvider_ALIPAY PaymentProvider = "ALIPAY" - PaymentProvider_PAYPAL PaymentProvider = "PAYPAL" - PaymentProvider_KLARNA PaymentProvider = "KLARNA" - PaymentProvider_AFTERPAY PaymentProvider = "AFTERPAY" - PaymentProvider_APPLEPAY PaymentProvider = "APPLEPAY" - PaymentProvider_GOOGLEPAY PaymentProvider = "GOOGLEPAY" - PaymentProvider_HEPSIPAY PaymentProvider = "HEPSIPAY" - PaymentProvider_STRIPE PaymentProvider = "STRIPE" - PaymentProvider_KASPI PaymentProvider = "KASPI" - PaymentProvider_MASLAK PaymentProvider = "MASLAK" - PaymentProvider_TOMPAY PaymentProvider = "TOMPAY" - PaymentProvider_TOM_FINANCE PaymentProvider = "TOM_FINANCE" - PaymentProvider_ALFABANK PaymentProvider = "ALFABANK" - PaymentProvider_PAYCELL PaymentProvider = "PAYCELL" - PaymentProvider_HASO PaymentProvider = "HASO" - PaymentProvider_OFFLINE PaymentProvider = "OFFLINE" + PaymentProvider_BANK PaymentProvider = "BANK" + PaymentProvider_CG_WALLET PaymentProvider = "CG_WALLET" + PaymentProvider_MASTERPASS PaymentProvider = "MASTERPASS" + PaymentProvider_GARANTI_PAY PaymentProvider = "GARANTI_PAY" + PaymentProvider_YKB_WORLD_PAY PaymentProvider = "YKB_WORLD_PAY" + PaymentProvider_PAPARA PaymentProvider = "PAPARA" + PaymentProvider_PAYONEER PaymentProvider = "PAYONEER" + PaymentProvider_SODEXO PaymentProvider = "SODEXO" + PaymentProvider_EDENRED PaymentProvider = "EDENRED" + PaymentProvider_ALIPAY PaymentProvider = "ALIPAY" + PaymentProvider_PAYPAL PaymentProvider = "PAYPAL" + PaymentProvider_KLARNA PaymentProvider = "KLARNA" + PaymentProvider_AFTERPAY PaymentProvider = "AFTERPAY" + PaymentProvider_APPLEPAY PaymentProvider = "APPLEPAY" + PaymentProvider_GOOGLEPAY PaymentProvider = "GOOGLEPAY" + PaymentProvider_HEPSIPAY PaymentProvider = "HEPSIPAY" + PaymentProvider_STRIPE PaymentProvider = "STRIPE" + PaymentProvider_KASPI PaymentProvider = "KASPI" + PaymentProvider_INSTANT_TRANSFER PaymentProvider = "INSTANT_TRANSFER" + PaymentProvider_MASLAK PaymentProvider = "MASLAK" + PaymentProvider_TOMPAY PaymentProvider = "TOMPAY" + PaymentProvider_TOM_FINANCE PaymentProvider = "TOM_FINANCE" + PaymentProvider_ALFABANK PaymentProvider = "ALFABANK" + PaymentProvider_PAYCELL PaymentProvider = "PAYCELL" + PaymentProvider_HASO PaymentProvider = "HASO" + PaymentProvider_OFFLINE PaymentProvider = "OFFLINE" ) // pos apm payment provider declaration @@ -181,20 +183,21 @@ const ( // payment method declaration const ( - PaymentMethod_CARD PaymentMethod = "CARD" - PaymentMethod_MASTERPASS PaymentMethod = "MASTERPASS" - PaymentMethod_PAPARA PaymentMethod = "PAPARA" - PaymentMethod_PAYONEER PaymentMethod = "PAYONEER" - PaymentMethod_SODEXO PaymentMethod = "SODEXO" - PaymentMethod_EDENRED PaymentMethod = "EDENRED" - PaymentMethod_EDENRED_GIFT PaymentMethod = "EDENRED_GIFT" - PaymentMethod_ALIPAY PaymentMethod = "ALIPAY" - PaymentMethod_PAYPAL PaymentMethod = "PAYPAL" - PaymentMethod_KLARNA PaymentMethod = "KLARNA" - PaymentMethod_AFTERPAY PaymentMethod = "AFTERPAY" - PaymentMethod_KASPI PaymentMethod = "KASPI" - PaymentMethod_TOMPAY PaymentMethod = "TOMPAY" - PaymentMethod_STRIPE PaymentMethod = "STRIPE" + PaymentMethod_CARD PaymentMethod = "CARD" + PaymentMethod_MASTERPASS PaymentMethod = "MASTERPASS" + PaymentMethod_PAPARA PaymentMethod = "PAPARA" + PaymentMethod_PAYONEER PaymentMethod = "PAYONEER" + PaymentMethod_SODEXO PaymentMethod = "SODEXO" + PaymentMethod_EDENRED PaymentMethod = "EDENRED" + PaymentMethod_EDENRED_GIFT PaymentMethod = "EDENRED_GIFT" + PaymentMethod_ALIPAY PaymentMethod = "ALIPAY" + PaymentMethod_PAYPAL PaymentMethod = "PAYPAL" + PaymentMethod_KLARNA PaymentMethod = "KLARNA" + PaymentMethod_AFTERPAY PaymentMethod = "AFTERPAY" + PaymentMethod_KASPI PaymentMethod = "KASPI" + PaymentMethod_INSTANT_TRANSFER PaymentMethod = "INSTANT_TRANSFER" + PaymentMethod_TOMPAY PaymentMethod = "TOMPAY" + PaymentMethod_STRIPE PaymentMethod = "STRIPE" ) // card type declaration @@ -352,6 +355,7 @@ const ( const ( ApmAdditionalAction_REDIRECT_TO_URL ApmAdditionalAction = "REDIRECT_TO_URL" ApmAdditionalAction_OTP_REQUIRED ApmAdditionalAction = "OTP_REQUIRED" + ApmAdditionalAction_SHOW_HTML_CONTENT ApmAdditionalAction = "SHOW_HTML_CONTENT" ApmAdditionalAction_WAIT_FOR_WEBHOOK ApmAdditionalAction = "WAIT_FOR_WEBHOOK" ApmAdditionalAction_APPROVAL_REQUIRED ApmAdditionalAction = "APPROVAL_REQUIRED" ApmAdditionalAction_NONE ApmAdditionalAction = "NONE" @@ -992,6 +996,7 @@ type InitCheckoutPaymentResponse struct { type InitApmPaymentResponse struct { PaymentId *int64 `json:"paymentId"` RedirectUrl *string `json:"redirectUrl"` + HtmlContent *string `json:"htmlContent"` PaymentStatus *PaymentStatus `json:"paymentStatus"` ApmAdditionalAction *ApmAdditionalAction `json:"additionalAction"` PaymentError *PaymentError `json:"paymentError"` @@ -1325,6 +1330,16 @@ type InstallmentResponse struct { InstallmentPrices []InstallmentPrice `json:"installmentPrices"` } +type InstantTransferBanksResponse struct { + Items []InstantTransferBank `json:"items"` +} + +type InstantTransferBank struct { + BankCode *string `json:"bankCode"` + BankName *string `json:"bankName"` + BankLogoUrl *string `json:"bankLogoUrl"` +} + type RetrieveBinNumberResponse struct { BinNumber *string `json:"binNumber"` CardType *string `json:"cardType"` @@ -1685,8 +1700,8 @@ type SearchPayoutCompletedTransactionsRequest struct { SettlementType SettlementType `schema:"settlementType,omitempty"` StartDate time.Time `schema:"startDate,omitempty"` EndDate time.Time `schema:"endDate,omitempty"` - Page int `schema:"page"` - Size int `schema:"size"` + Page int `schema:"page"` + Size int `schema:"size"` } type SearchPayoutBouncedTransactionsRequest struct { diff --git a/adapter/payment.go b/adapter/payment.go index 5ca00ea..c2204bd 100644 --- a/adapter/payment.go +++ b/adapter/payment.go @@ -553,6 +553,20 @@ func (api *Payment) ApproveBnplPayment(ctx context.Context, paymentId int64) err return nil } +func (api *Payment) RetrieveActiveBanks(ctx context.Context) (*InstantTransferBanksResponse, error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, "/payment/v1/instant-transfer-banks", nil) + if err != nil { + return nil, err + } + response := &Response[InstantTransferBanksResponse]{} + err = api.Client.Do(ctx, newRequest, response) + if err != nil { + return nil, err + } + + return response.Data, nil +} + func (c *Payment) Is3DSecureCallbackVerified(threeDSecureCallbackKey string, params map[string]string) bool { hash := params["hash"] hashString := strings.Join([]string{threeDSecureCallbackKey, diff --git a/tests/instant_transfer_payment_test.go b/tests/instant_transfer_payment_test.go new file mode 100644 index 0000000..ee30319 --- /dev/null +++ b/tests/instant_transfer_payment_test.go @@ -0,0 +1,53 @@ +package tests + +import ( + "context" + "testing" + + "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" +) + +var instantTransferPaymentClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io") + +func TestRetrieveActiveBanks(t *testing.T) { + res, err := instantTransferPaymentClient.Payment.RetrieveActiveBanks(context.Background()) + require.NotEmpty(t, res.Items) + if err != nil { + t.Errorf("Error %s", err) + } +} + +func TestInitInstantTransferAPMPayment(t *testing.T) { + additionalParams := make(map[string]string) + additionalParams["bankCode"] = "0" + + request := adapter.InitApmPaymentRequest{ + ApmType: craftgate.ApmType_INSTANT_TRANSFER, + Price: 1, + PaidPrice: 1, + Currency: craftgate.Currency_TRY, + PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION, + ConversationId: "foo-bar", + CallbackUrl: "https://www.your-website.com/callback", + Items: []craftgate.PaymentItem{ + { + Name: "Item 1", + Price: 0.6, + }, + { + Name: "Item 2", + Price: 0.4, + }, + }, + AdditionalParams: additionalParams, + } + res, err := instantTransferPaymentClient.Payment.InitApmPayment(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} From d353f486f424b25f6f13b80d7dbaab8da7bfa846 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Mar 2024 09:51:40 +0300 Subject: [PATCH 29/30] Bump github.com/stretchr/testify from 1.8.4 to 1.9.0 (#74) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.4 to 1.9.0. - [Release notes](https://github.com/stretchr/testify/releases) - [Commits](https://github.com/stretchr/testify/compare/v1.8.4...v1.9.0) --- updated-dependencies: - dependency-name: github.com/stretchr/testify dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sabri Onur Tüzün <335067+sotuzun@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 5f6e7d0..969e57f 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/davecgh/go-spew v1.1.1 github.com/gorilla/schema v1.2.1 - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 ) require ( diff --git a/go.sum b/go.sum index e0d170a..e84444b 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/gorilla/schema v1.2.1 h1:tjDxcmdb+siIqkTNoV+qRH2mjYdr2hHe5MKXbp61ziM= github.com/gorilla/schema v1.2.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= From 1e3bc06680336b36269aeff372cda4febe08bee5 Mon Sep 17 00:00:00 2001 From: Onur Polattimur Date: Fri, 22 Mar 2024 15:01:15 +0300 Subject: [PATCH 30/30] Add GarantiPay v2 integration (#75) --- adapter/model.go | 7 ++++--- tests/payment_test.go | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/adapter/model.go b/adapter/model.go index e010520..93c28d8 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -127,9 +127,10 @@ const ( // pos apm payment provider declaration const ( - PosApmPaymentProvider_YKB_WORLD_PAY PosApmPaymentProvider = "YKB_WORLD_PAY" - PosApmPaymentProvider_APPLEPAY PosApmPaymentProvider = "APPLEPAY" - PosApmPaymentProvider_GOOGLEPAY PosApmPaymentProvider = "GOOGLEPAY" + PosApmPaymentProvider_YKB_WORLD_PAY PosApmPaymentProvider = "YKB_WORLD_PAY" + PosApmPaymentProvider_YKB_WORLD_PAY_SHOPPING_LOAN PosApmPaymentProvider = "YKB_WORLD_PAY_SHOPPING_LOAN" + PosApmPaymentProvider_GOOGLEPAY PosApmPaymentProvider = "GOOGLEPAY" + PosApmPaymentProvider_GARANTI_PAY PosApmPaymentProvider = "GARANTI_PAY" ) // payment status declaration diff --git a/tests/payment_test.go b/tests/payment_test.go index 881d4f5..bbbeab2 100644 --- a/tests/payment_test.go +++ b/tests/payment_test.go @@ -533,7 +533,7 @@ func TestPayment_CompleteApmPayment(t *testing.T) { } } -func TestPayment_InitPosApmPayment(t *testing.T) { +func TestPayment_InitYkbWorldPayPosApmPayment(t *testing.T) { request := adapter.InitPosApmPaymentRequest{ Price: 1.25, PaidPrice: 1.25, @@ -566,6 +566,39 @@ func TestPayment_InitPosApmPayment(t *testing.T) { } } +func TestPayment_InitGarantiPayPosApmPayment(t *testing.T) { + request := adapter.InitPosApmPaymentRequest{ + Price: 1.25, + PaidPrice: 1.25, + Currency: craftgate.Currency_TRY, + PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION, + ConversationId: "foo-bar", + PaymentProvider: craftgate.PosApmPaymentProvider_GARANTI_PAY, + CallbackUrl: "https://www.your-website.com/callback", + Items: []craftgate.PaymentItem{ + { + Name: "Item 1", + Price: 1, + ExternalId: "1", + }, + { + Name: "Item 2", + Price: 0.25, + ExternalId: "2", + }, + }, + AdditionalParams: map[string]string{ + "integrationType": "WEB2APP", + }, + } + res, err := paymentClient.Payment.InitPosApmPayment(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} + func TestPayment_CompletePosApmPayment(t *testing.T) { request := adapter.CompletePosApmPaymentRequest{ PaymentId: 123,