papara

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

Papara Go API Client

This library makes it easy to interact with the Papara API.

Supported APIs

  • Account API
  • User Verification API
  • Pay with Papara API
  • Pay with Vpos API
  • Pay with QR API
  • Pay with Link API
  • Mass Payment API

Installation

go get github.com/9ssi7/papara

Usage

import (
	"fmt"
	"github.com/9ssi7/papara"
)

func main() {
	// Set your API key and URL
	apiKey := "YOUR_API_KEY"
	apiUrl := "YOUR_API_URL"

	// Create a new Papara client
	client := papara.New(papara.Config{
		ApiKey: apiKey,
		ApiUrl: apiUrl,
	})

	// Get account information
	account, err := client.Account()
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("Account Information:")
	fmt.Println("  ID:", account.Data.ID)
	fmt.Println("  Balance:", account.Data.Balances[0].TotalBalance)

	// Create a payment
	payment, err := client.CreatePayment(papara.PaymentCreateRequest{
		Amount:              100.0,
		ReferenceId:         "ORDER-1234",
		OrderDescription:    "Order #1234",
		NotificationUrl:     "https://your-website.com/callback",
		FailNotificationUrl: "https://your-website.com/fail-callback",
		RedirectUrl:         "https://your-website.com/success",
	})
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("Payment Created:")
	fmt.Println("  ID:", payment.Data.ID)
	fmt.Println("  Payment URL:", payment.Data.PaymentUrl)
}

Contributing

If you want to contribute to this library, you are welcome to send pull requests or open issues on Github.

Documentation

Overview

Package papara provides functions for interacting with the Papara API

Package papara provides functions for interacting with the Papara API.

Package papara provides functions for interacting with the Papara API.

Package papara provides functions for interacting with the Papara API.

Package papara provides functions for interacting with the Papara API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountLedgersFilterRequest

type AccountLedgersFilterRequest struct {
	StartDate     string `json:"startDate"`
	EndDate       string `json:"endDate"`
	Page          int    `json:"page"`
	PageSize      int    `json:"pageSize"`
	EntryType     *int   `json:"entryType,omitempty"`
	AccountNumber *int   `json:"accountNumber,omitempty"`
}

AccountLedgersFilterRequest is a struct representing the request parameters for the AccountLedgers method.

type AccountLedgersResult

type AccountLedgersResult struct {
	Data struct {
		Items []struct {
			Id            int    `json:"id"`
			CreatedAt     string `json:"createdAt"`
			EntryType     int    `json:"entryType"`
			EntryTypeName string `json:"entryTypeName"`
			Amount        int    `json:"amount"`
			Fee           int    `json:"fee"`
			Currency      int    `json:"currency"`
			CurrencyInfo  struct {
				CurrencyEnum         int    `json:"currencyEnum"`
				Symbol               string `json:"symbol"`
				Code                 string `json:"code"`
				PreferredDisplayCode string `json:"preferredDisplayCode"`
				Name                 string `json:"name"`
				IsCryptocurrency     bool   `json:"isCryptocurrency"`
				Precision            int    `json:"precision"`
				IconUrl              string `json:"iconUrl"`
			} `json:"currencyInfo"`
			ResultingBalance           int    `json:"resultingBalance"`
			Description                string `json:"description"`
			MassPaymentId              *int   `json:"massPaymentId,omitempty"`
			CheckoutPaymentId          *int   `json:"checkoutPaymentId,omitempty"`
			CheckoutPaymentReferenceId *int   `json:"checkoutPaymentReferenceId,omitempty"`
		} `json:"items"`
		Page           int `json:"page"`
		PageItemCount  int `json:"pageItemCount"`
		TotalItemCount int `json:"totalItemCount"`
		TotalPageCount int `json:"totalPageCount"`
		PageSkip       int `json:"pageSkip"`
	} `json:"data"`
	Succeeded            bool         `json:"succeeded"`
	Error                *ErrorResult `json:"error"`
	ServiceResultSuccess any          `json:"serviceResultSuccess"`
}

AccountLedgersResult is a struct representing the account ledger result from the Papara API.

type AccountResult

type AccountResult struct {
	Data      *AccountResultData `json:"data"`
	Succeeded bool               `json:"succeeded"`
	Error     *ErrorResult       `json:"error"`
}

AccountResult is a struct representing the complete account result from the Papara API.

type AccountResultData

type AccountResultData struct {
	ID       string `json:"id"`
	Balances []struct {
		Currency         int     `json:"currency"`
		TotalBalance     float64 `json:"totalBalance"`
		LockedBalance    float64 `json:"lockedBalance"`
		AvailableBalance float64 `json:"availableBalance"`
		Iban             any     `json:"iban"`
		CurrencyInfo     struct {
			CurrencyEnum                         int    `json:"currencyEnum"`
			Symbol                               string `json:"symbol"`
			Code                                 string `json:"code"`
			Number                               int    `json:"number"`
			PreferredDisplayCode                 string `json:"preferredDisplayCode"`
			Name                                 string `json:"name"`
			IsCryptocurrency                     bool   `json:"isCryptocurrency"`
			IsInternationalMoneyTransferCurrency bool   `json:"isInternationalMoneyTransferCurrency"`
			Precision                            int    `json:"precision"`
			IconURL                              string `json:"iconUrl"`
			FlagURL                              string `json:"flagUrl"`
			CurrencyEnumIso                      int    `json:"currencyEnumIso"`
			IsMetalCurrency                      bool   `json:"isMetalCurrency"`
		} `json:"currencyInfo"`
	} `json:"balances"`
	LegalName           string `json:"legalName"`
	IconURL             any    `json:"iconUrl"`
	BrandName           string `json:"brandName"`
	AllowedPaymentTypes []struct {
		PaymentMethod int `json:"paymentMethod"`
	} `json:"allowedPaymentTypes"`
	AllowingGuestCheckout                  bool `json:"allowingGuestCheckout"`
	IsCorporateCardsListOnPaparaAppEnabled bool `json:"isCorporateCardsListOnPaparaAppEnabled"`
	AtmDepositEnabled                      bool `json:"atmDepositEnabled"`
}

AccountResultData is a struct representing account data returned by the Papara API.

type AccountSettlementRequest

type AccountSettlementRequest struct {
	StartDate string `json:"startDate"`
	EndDate   string `json:"endDate"`
	EntryType *int   `json:"entryType,omitempty"`
}

AccountSettlementRequest is a struct representing the request parameters for the AccountSettlement method.

type AccountSettlementResult

type AccountSettlementResult struct {
	Data struct {
		Count  int `json:"count"`
		Volume int `json:"volume"`
	} `json:"data"`
	Succeeded bool         `json:"succeeded"`
	Error     *ErrorResult `json:"error"`
}

type BasicResult

type BasicResult struct {
	Succeeded bool         `json:"succeeded"`
	Error     *ErrorResult `json:"error"`
}

type Config

type Config struct {
	// ApiKey is the Papara API key.
	ApiKey string `env:"PAPARA_API_KEY"`

	// ApiUrl is the base URL for the Papara API.
	ApiUrl string `env:"PAPARA_API_URL"`
}

Config represents the configuration for the Papara client.

type ErrorResult

type ErrorResult struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

type PaymentCreateRequest

type PaymentCreateRequest struct {
	Amount              float64 `json:"amount"`
	ReferenceId         string  `json:"referenceId"`
	OrderDescription    string  `json:"orderDescription"`
	NotificationUrl     string  `json:"notificationUrl"`
	FailNotificationUrl string  `json:"failNotificationUrl"`
	RedirectUrl         string  `json:"redirectUrl"`
	TurkishNationalId   *string `json:"turkishNationalId,omitempty"`
	Currency            *int    `json:"currency,omitempty"`
}

PaymentCreateRequest is a struct representing the request parameters for the CreatePayment method.

type PaymentCreateResult

type PaymentCreateResult struct {
	Data struct {
		Merchant struct {
			LegalName           string `json:"legalName"`
			BrandName           string `json:"brandName"`
			AllowedPaymentTypes []struct {
				PaymentMethod int `json:"paymentMethod"`
			} `json:"allowedPaymentTypes"`
			Balances []struct {
				Currency         int `json:"currency"`
				TotalBalance     int `json:"totalBalance"`
				LockedBalance    int `json:"lockedBalance"`
				AvailableBalance int `json:"availableBalance"`
			} `json:"balances"`
		} `json:"merchant"`
		UserId                   string `json:"userId"`
		PaymentMethod            int    `json:"paymentMethod"`
		PaymentMethodDescription string `json:"paymentMethodDescription"`
		ReferenceId              string `json:"referenceId"`
		OrderDescription         string `json:"orderDescription"`
		Status                   int    `json:"status"`
		StatusDescription        string `json:"statusDescription"`
		Amount                   int    `json:"amount"`
		Fee                      int    `json:"fee"`
		Currency                 int    `json:"currency"`
		NotificationUrl          string `json:"notificationUrl"`
		NotificationDone         bool   `json:"notificationDone"`
		RedirectUrl              string `json:"redirectUrl"`
		PaymentUrl               string `json:"paymentUrl"`
		MerchantSecretKey        string `json:"merchantSecretKey"`
		ReturningRedirectUrl     string `json:"returningRedirectUrl"`
		TurkishNationalId        int    `json:"turkishNationalId"`
		Id                       string `json:"id"`
		CreatedAt                string `json:"createdAt"`
	} `json:"data"`
	Succeeded bool         `json:"succeeded"`
	Error     *ErrorResult `json:"error"`
}

type PaymentGetResult

type PaymentGetResult struct {
	Data struct {
		Merchant struct {
			ID       string `json:"id"`
			Balances []struct {
				Currency         int     `json:"currency"`
				TotalBalance     float64 `json:"totalBalance"`
				LockedBalance    float64 `json:"lockedBalance"`
				AvailableBalance float64 `json:"availableBalance"`
				Iban             any     `json:"iban"`
				CurrencyInfo     struct {
					CurrencyEnum                         int    `json:"currencyEnum"`
					Symbol                               string `json:"symbol"`
					Code                                 string `json:"code"`
					Number                               int    `json:"number"`
					PreferredDisplayCode                 string `json:"preferredDisplayCode"`
					Name                                 string `json:"name"`
					IsCryptocurrency                     bool   `json:"isCryptocurrency"`
					IsInternationalMoneyTransferCurrency bool   `json:"isInternationalMoneyTransferCurrency"`
					Precision                            int    `json:"precision"`
					IconURL                              string `json:"iconUrl"`
					FlagURL                              string `json:"flagUrl"`
					CurrencyEnumIso                      int    `json:"currencyEnumIso"`
					IsMetalCurrency                      bool   `json:"isMetalCurrency"`
				} `json:"currencyInfo"`
			} `json:"balances"`
			LegalName           string `json:"legalName"`
			IconURL             any    `json:"iconUrl"`
			BrandName           string `json:"brandName"`
			AllowedPaymentTypes []struct {
				PaymentMethod int `json:"paymentMethod"`
			} `json:"allowedPaymentTypes"`
			AllowingGuestCheckout                  bool `json:"allowingGuestCheckout"`
			IsCorporateCardsListOnPaparaAppEnabled bool `json:"isCorporateCardsListOnPaparaAppEnabled"`
			AtmDepositEnabled                      bool `json:"atmDepositEnabled"`
		} `json:"merchant"`
		UserName                 any     `json:"userName"`
		RelatedTransactions      []any   `json:"relatedTransactions"`
		TotalRefundedAmount      float64 `json:"totalRefundedAmount"`
		ID                       string  `json:"id"`
		CreatedAt                string  `json:"createdAt"`
		MerchantID               string  `json:"merchantId"`
		UserID                   any     `json:"userId"`
		PaymentMethod            int     `json:"paymentMethod"`
		PaymentMethodDescription string  `json:"paymentMethodDescription"`
		ReferenceID              string  `json:"referenceId"`
		OrderDescription         string  `json:"orderDescription"`
		Status                   int     `json:"status"`
		StatusDescription        string  `json:"statusDescription"`
		Amount                   float64 `json:"amount"`
		Fee                      float64 `json:"fee"`
		Currency                 int     `json:"currency"`
		CurrencyInfo             struct {
			CurrencyEnum                         int    `json:"currencyEnum"`
			Symbol                               string `json:"symbol"`
			Code                                 string `json:"code"`
			Number                               int    `json:"number"`
			PreferredDisplayCode                 string `json:"preferredDisplayCode"`
			Name                                 string `json:"name"`
			IsCryptocurrency                     bool   `json:"isCryptocurrency"`
			IsInternationalMoneyTransferCurrency bool   `json:"isInternationalMoneyTransferCurrency"`
			Precision                            int    `json:"precision"`
			IconURL                              string `json:"iconUrl"`
			FlagURL                              string `json:"flagUrl"`
			CurrencyEnumIso                      int    `json:"currencyEnumIso"`
			IsMetalCurrency                      bool   `json:"isMetalCurrency"`
		} `json:"currencyInfo"`
		NotificationURL       string `json:"notificationUrl"`
		FailNotificationURL   any    `json:"failNotificationUrl"`
		NotificationDone      bool   `json:"notificationDone"`
		PaymentURL            string `json:"paymentUrl"`
		MerchantSecretKey     any    `json:"merchantSecretKey"`
		RemainingRefundAmount any    `json:"remainingRefundAmount"`
		ReturningRedirectURL  string `json:"returningRedirectUrl"`
		ErrorCode             any    `json:"errorCode"`
		ErrorMessage          any    `json:"errorMessage"`
		TurkishNationalID     int    `json:"turkishNationalId"`
	} `json:"data"`
	Succeeded bool         `json:"succeeded"`
	Error     *ErrorResult `json:"error"`
}

type PaymentRefundRequest

type PaymentRefundRequest struct {
	PaymentId    string `json:"paymentId"`
	RefundAmount string `json:"refundAmount"`
}

PaymentRefundRequest is a struct representing the request parameters for the RefundPayment method.

type PaymentResultNotification

type PaymentResultNotification struct {
	MerchantId               string  `json:"merchantId"`
	UserId                   string  `json:"userId"`
	PaymentMethod            int     `json:"paymentMethod"`
	PaymentMethodDescription string  `json:"paymentMethodDescription"`
	ReferenceId              string  `json:"referenceId"`
	OrderDescription         string  `json:"orderDescription"`
	Status                   int     `json:"status"`
	StatusDescription        string  `json:"statusDescription"`
	Amount                   float64 `json:"amount"`
	Fee                      float64 `json:"fee"`
	Currency                 string  `json:"currency"`
	NotificationUrl          string  `json:"notificationUrl"`
	NotificationDone         bool    `json:"notificationDone"`
	RedirectUrl              string  `json:"redirectUrl"`
	MerchantSecretKey        string  `json:"merchantSecretKey"`
	PaymentUrl               string  `json:"paymentUrl"`
	ReturningRedirectUrl     string  `json:"returningRedirectUrl"`
	Id                       string  `json:"id"`
	CreatedAt                string  `json:"createdAt"`
	TurkishNationalId        string  `json:"turkishNationalId"`
}

PaymentResultNotification is a struct representing a payment result notification from Papara. Papara calls the notification URL with this struct when a payment is completed. If papara does not call the notification URL, the payment is not considered complete.

type Service

type Service interface {

	// Account method retrieves the account information for the current user.
	Account() (*AccountResult, error)

	// AccountLedgers method retrieves the account ledger for the current user.
	AccountLedgers(req AccountLedgersFilterRequest) (*AccountLedgersResult, error)

	// AccountSettlement method retrieves the account settlement for the current user.
	AccountSettlement(req AccountSettlementRequest) (*AccountSettlementResult, error)

	// ValidateWithAccountNumber method validates an account with an account number.
	ValidateWithAccountNumber(accountNumber int) (*ValidationResult, error)

	// ValidateWithPhoneNumber method validates a account with a phone number.
	ValidateWithPhoneNumber(phoneNumber string) (*ValidationResult, error)

	// ValidateWithTckn method validates a account with a Turkish national ID.
	ValidateWithTckn(tckn string) (*ValidationResult, error)

	// CreatePayment method creates a new payment.
	CreatePayment(req PaymentCreateRequest) (*PaymentCreateResult, error)

	// GetPayment method retrieves a payment by ID.
	GetPayment(paymentId string) (*PaymentGetResult, error)

	// CancelPayment method cancels a payment by ID.
	CancelPayment(paymentId string) (*BasicResult, error)

	// RefundPayment method refunds a payment.
	RefundPayment(req PaymentRefundRequest) (*BasicResult, error)
}

Service interface defines the methods for interacting with the Papara API.

func New

func New(cnf Config) Service

New function creates a new Papara client.

type ValidationResult

type ValidationResult struct {
	Data struct {
		UserId        string `json:"userId"`
		FirstName     string `json:"firstName"`
		LastName      string `json:"lastName"`
		Tckn          string `json:"tckn"`
		AccountNumber int    `json:"accountNumber"`
	} `json:"data"`
	Succeeded bool         `json:"succeeded"`
	Error     *ErrorResult `json:"error"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL