consumer

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

Package consumer contains all of apis regarding EBS Consumer Web services the package is structured in such a way that separetes between the payment apis and the [services] apis.

Payment APIs All of the payment apis are in [payment_apis.go] file, they include basically all of EBS Consumer web service docs [v3.0.0].

Helper APIs We also have help apis in [services.go]

Package consumer provides services for EBS consumer APIs, and custom apis we have developed as well. It offers a seamless and unified api to be used for both merchant pos and mobile payment

EBS Services

- Get Balance

- Working Key

- Is Alive

- Card transfer

- Billers

Special Payment

Special Payment is a secure way to tokenize payments for external service providers through a custom url link. The URL is only valid once and it cannot be reused.

Workflow

Here's how the system works.

- Generate a payment token (/consumer/generate_token)

Parameters: - amount

- biller id

It will return a new response with a UUID that to be used by the client's users for payment.

- Special payment (/consumer/special_payment/:UUID)

Parameters:

- tranAmount (the same as before!)

- billerId

- ConsumerServices payload

It will return 400 ONLY if the amount OR the biller id didn't match the specified UUID in the system

Examples

cURL:

1. Generate Token curl -X POST https://api.soluspay.net/api/v1/payment_token -d '{"amount": 10}'

> {"result":{"amount":10,"uuid":"6eb3ae20-ecbc-4603-b079-ed98549cf9f2"},"uuid":"6eb3ae20-ecbc-4603-b079-ed98549cf9f2"}

2. Inquire token via UUID curl -X GET https://api.soluspay.net/api/v1/payment/6eb3ae20-ecbc-4603-b079-ed98549cf9f2 -d '{"amount": 10}'

3. Complete Payment curl -X POST https://api.soluspay.net/api/v1/payment/6eb3ae20-ecbc-4603-b079-ed98549cf9f2 -d '{"amount": 10}'

NOTE that in payment inquiry we use GET method, while we use POST for payment

* Note authentication might be added to this API

PIN Block

Please advice with ebs documentations about iPIN block encryption. You can cite these locations for iPIN implementation:

- https://github.com/adonese/donates (JS) - https://github.com/adonese/noebs-wasm (GO) - https://github.com/adonese/cashq (Java)

Index

Constants

View Source
const (
	SPECIAL_BILLERS = "noebs:billers"
	KEY             = "publickey_"
)
View Source
const (
	EBS_NOTIFICATION       = "ebs"
	NOEBS_NOTIFICATION     = "noebs"
	MARKETING_NOTIFICATION = "marketing"
	OTHERS_NOTIFICATIONS   = "others"
	CTA_CARD_TRANSFER      = "card_transfer"
	CTA_BALANCE            = "balance"
	CTA_BILL_PAYMENT       = "bill_payment"
	CTA_VOUCHER            = "voucher"
	CTA_REQUEST_FUNDS      = "request_funds"
	CTA_OTHERS             = "others"
)

various consts we are using for push data and notifications

View Source
const (
	SMS_GATEWAY = "https://mazinhost.com/smsv1/sms/api?action=send-sms"
)

Variables

View Source
var (
	ErrCreateDbRow = errors.New("unable to create a new db row/column")
)

Functions

func GetRandomName

func GetRandomName(retry int) string

GetRandomName generates a random name from the list of adjectives and surnames in this package formatted as "adjective_surname". For example 'focused_turing'. If retry is non-zero, a random integer between 0 and 10 will be added to the end of the name, e.g `focused_turing3`

Types

type Auther

type Auther interface {
	VerifyJWT(token string) (*gateway.TokenClaims, error)
	GenerateJWT(token string) (string, error)
}

type PushData added in v0.3.0

type PushData struct {
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
	Type      string         `json:"type"`
	Date      int64          `json:"date" gorm:"autoCreateTime"`
	UUID      string         `gorm:"primaryKey"`
	// To could be a phone number a bill id a card number, you name it
	To             string                 `json:"to"`
	Title          string                 `json:"title"`
	Body           string                 `json:"body"`
	EBSData        ebs_fields.EBSResponse `json:"data" gorm:"foreignKey:UUID;references:UUID"` // EBS parser fields holds many unnecssary info
	PaymentRequest ebs_fields.QrData      `json:"payment_request" gorm:"foreignKey:UUID"`
	CallToAction   string                 `json:"call_to_action"`
	// We use phone field to store a reference to the mobile number for both the sender and the receiver
	// for future reference to be queried.
	Phone    string `json:"phone"`
	IsRead   bool   `json:"is_read"`
	DeviceID string `json:"device_id"`
}

PushData is a database table we use to push notifications to their users. It has a one-to-one reference to transactions Table and a noebs Token (if needed)

func (*PushData) UpdateIsRead added in v0.3.0

func (p *PushData) UpdateIsRead(phone string, db *gorm.DB)

type Service

type Service struct {
	Redis       *redis.Client
	Db          *gorm.DB
	NoebsConfig ebs_fields.NoebsConfig
	Logger      *logrus.Logger
	FirebaseApp *firebase.App
	Auth        Auther
}

Service consumer for utils.Service struct

func (*Service) APIAuth

func (s *Service) APIAuth() gin.HandlerFunc

APIAuth API-Key middleware. Currently is used by consumer services

func (*Service) AccountTransfer

func (s *Service) AccountTransfer(c *gin.Context)

AccountTransfer performs p2p transactions

func (*Service) AddCards

func (s *Service) AddCards(c *gin.Context)

AddCards Allow users to add card to their profile if main_card was set to true, then it will be their main card AND it will remove the previously selected one FIXME

func (*Service) AddFirebaseID added in v0.3.0

func (s *Service) AddFirebaseID(c *gin.Context)

func (*Service) ApiKeyMiddleware

func (s *Service) ApiKeyMiddleware(c *gin.Context)

ApiKeyMiddleware used to authenticate clients using X-Email and X-API-Key headers FIXME issue #58 #61

func (*Service) Balance

func (s *Service) Balance(c *gin.Context)

Balance gets performs get balance transaction for the provided card info

func (*Service) BalanceStep added in v0.3.0

func (s *Service) BalanceStep(c *gin.Context)

BalanceStep part of our 2fa steps for account recovery

func (*Service) Beneficiaries added in v0.3.0

func (s *Service) Beneficiaries(c *gin.Context)

Beneficiaries manage all of beneficiaries data

func (*Service) BillInquiry

func (s *Service) BillInquiry(c *gin.Context)

BillInquiry for telecos, utility and government (billers inquiries)

func (*Service) BillPayment

func (s *Service) BillPayment(c *gin.Context)

BillPayment is responsible for utility, telecos, e-government and other payment services

func (Service) BillerHooks added in v0.3.0

func (s Service) BillerHooks()

BillerHooks submits results to external endpoint

func (*Service) CardFromNumber

func (s *Service) CardFromNumber(c *gin.Context)

CardFromNumber gets the gussesed associated mobile number to this pan

func (*Service) CardTransfer

func (s *Service) CardTransfer(c *gin.Context)

CardTransfer performs p2p transactions

func (*Service) CashIn

func (s *Service) CashIn(c *gin.Context)

CashIn performs cash in transactions

func (*Service) CashOut

func (s *Service) CashOut(c *gin.Context)

CashOut performs cashout transactions

func (*Service) CashoutPub

func (s *Service) CashoutPub()

CashoutPub experimental support to add pubsub support we need to make this api public

func (*Service) ChangePassword

func (s *Service) ChangePassword(c *gin.Context)

ChangePassword used to change a user's password using their old one

func (*Service) CompleteIpin

func (s *Service) CompleteIpin(c *gin.Context)

CompleteIpin performs an otp check from ebs to complete ipin change transaction

func (*Service) CompleteRegistration

func (s *Service) CompleteRegistration(c *gin.Context)

CompleteRegistration step 2 in card issuance process

func (*Service) CreateUser

func (s *Service) CreateUser(c *gin.Context)

CreateUser to register a new user to noebs

func (*Service) EbsGetCardInfo

func (s *Service) EbsGetCardInfo(c *gin.Context)

EbsGetCardInfo get card holder name from pan. Currently is limited to telecos only

func (*Service) EditCard

func (s *Service) EditCard(c *gin.Context)

EditCard allow authorized users to edit their cards (e.g., edit pan / expdate) this updates any card via

func (*Service) GenerateAPIKey

func (s *Service) GenerateAPIKey(c *gin.Context)

GenerateAPIKey An Admin-only endpoint that is used to generate api key for our clients the user must submit their email to generate a unique token per email. FIXME #59 #58 #61 api generation should be decoupled from apigateway package

func (*Service) GenerateIpin

func (s *Service) GenerateIpin(c *gin.Context)

GenerateIpin generates a new ipin for card holder

func (*Service) GeneratePaymentToken

func (s *Service) GeneratePaymentToken(c *gin.Context)

GeneratePaymentToken is used by noebs user to charge their customers. the toCard field in `Token` uses a masked PAN (first 6 digits and last 4 digits and any number of * in between)

func (*Service) GenerateSignInCode

func (s *Service) GenerateSignInCode(c *gin.Context, allowInsecure bool)

GenerateSignInCode allows noebs users to access their accounts in case they forgotten their passwords

func (*Service) GenerateVoucher

func (s *Service) GenerateVoucher(c *gin.Context)

QRPayment performs QR payment transaction

func (*Service) GetBiller added in v0.3.0

func (s *Service) GetBiller(c *gin.Context)

BillerID retrieves a billerID from noebs and performs an ebs request if a phone number doesn't exist in our system

func (*Service) GetBills

func (s *Service) GetBills(c *gin.Context)

GetBills for any EBS supported bill just by the entityID (phone number or the invoice ID). A good abstraction over EBS services. The function also updates a local database for each result for subsequent queries.

func (*Service) GetCards

func (s *Service) GetCards(c *gin.Context)

GetCards Get all cards for the currently authorized user

func (*Service) GetIpinPubKey added in v0.3.0

func (s *Service) GetIpinPubKey() error

func (*Service) GetMSISDNFromCard

func (s *Service) GetMSISDNFromCard(c *gin.Context)

GetMSISDNFromCard for ussd to get pan info from sim card

func (*Service) GetPaymentToken

func (s *Service) GetPaymentToken(c *gin.Context)

GetPaymentToken retrieves a generated payment token by UUID This service should be accessed via an authorization header

func (*Service) IPINKey

func (s *Service) IPINKey(c *gin.Context)

CompleteIpin performs an otp check from ebs to complete ipin change transaction

func (*Service) IPinChange

func (s *Service) IPinChange(c *gin.Context)

IPinChange changes the ipin for the card holder provided card

func (*Service) IpFilterMiddleware

func (s *Service) IpFilterMiddleware(c *gin.Context)

FIXME issue #58 #61

func (*Service) IsAlive

func (s *Service) IsAlive(c *gin.Context)

IsAlive performs isAlive request to inquire for ebs server availability

func (*Service) LoginHandler

func (s *Service) LoginHandler(c *gin.Context)

LoginHandler noebs signin page

func (*Service) NecToName

func (s *Service) NecToName(c *gin.Context)

NecToName gets an nec number from the context and maps it to its meter number

func (*Service) NoebsQuickPayment

func (s *Service) NoebsQuickPayment(c *gin.Context)

NoebsQuickPayment performs a QR or payment via url transaction The api should be like this, and it should work for both the mobile and the web clients The very unique thing about the full payment token is that it is self-containted, the implmenter doesn't have to do an http call to inquire about its fields but, let's walkthrough the process, should we used a uuid of the payment token instead. - a user will click on an item - the app or web will make a call to generate a payment token - and it will return a link and a payment token. the link, or noebs link is only valid in the case of noebs' vendors payments (e.g., Solus or tuti): in that, it cannot work for the case of ecommerce - there are two cases for using the endpoint: - using the full-token should render the forms to show the details of the token (toCard, amount, and any comments) - using the uuid only, should be followed by the client performing a request to get the token info request body fields should always take precendents over query params

func (*Service) Notifications added in v0.3.0

func (s *Service) Notifications(c *gin.Context)

Notifications handles various crud operations (json)

func (*Service) PaymentOrder

func (s *Service) PaymentOrder() gin.HandlerFunc

PaymentOrder used to perform a transaction on behalf of a noebs user. This api should be used behind an authorization middleware The goal of this api is to allow our customers to perform certain types of transactions (recurred ones) without having to worry about it. For example, if a user wants to make saving, or in case they want to they want to pay for their rent. Recurring payment scenarios are a lot. The current proposal is to use a _wallet_. Simply, a user will put a money into noebs bank account. Whenever a user want to perform a recurred payment, noebs can then use their wallet to perform the transaction.

## Problems we have so far - We are not allowed to store value, we cannot save users money in our account - We cannot store user's payment information (pan, ipin, exp date) in our system - And we don't want the user to everytime login into the app and key in their payment information

func (*Service) Purchase

func (s *Service) Purchase(c *gin.Context)

Purchase performs special payment api from ebs consumer services It requires: card info (src), amount fields, specialPaymentId (destination) in order to complete the transaction

func (*Service) Pusher added in v0.3.0

func (s *Service) Pusher()

func (*Service) QRComplete

func (s *Service) QRComplete(c *gin.Context)

QRRefund performs qr refund transaction

func (*Service) QRGeneration

func (s *Service) QRGeneration(c *gin.Context)

QRGeneration generates a qr token for the registered merchant

func (*Service) QRMerchantRegistration

func (s *Service) QRMerchantRegistration(c *gin.Context)

CashIn performs cash in transactions

func (*Service) QRPayment

func (s *Service) QRPayment(c *gin.Context)

QRPayment performs QR payment transaction. This is EBS-based QR transaction, and to be confused with noebs one

func (*Service) QRRefund

func (s *Service) QRRefund(c *gin.Context)

QRRefund performs qr refund transaction

func (*Service) QRTransactions

func (s *Service) QRTransactions(c *gin.Context)

QRRefund performs qr refund transaction

func (*Service) RefreshHandler

func (s *Service) RefreshHandler(c *gin.Context)

RefreshHandler generates a new access token to the user using their signed public key. the user will sign their username with their private key, and noebs will verify the signature using the stored public key for the user

func (*Service) RegisterCard

func (s *Service) RegisterCard(c *gin.Context)

QRPayment performs QR payment transaction

func (*Service) RegisterWithCard added in v0.3.0

func (s *Service) RegisterWithCard(c *gin.Context)

Register with card allow a user to register through noebs and assigning a card to them

func (*Service) RemoveCard

func (s *Service) RemoveCard(c *gin.Context)

RemoveCard allow authorized users to remove their card when the send the card id (from its list in app view)

func (*Service) RequestFunds added in v0.3.0

func (s *Service) RequestFunds(c *gin.Context)

GeneratePaymentToken is used by noebs user to charge their customers. This is also used to generate a payment link that can be used by tuti users to perfom online payments RequestFunds is used by noebs users to request money from other noebs users.

func (*Service) SendPush added in v0.3.0

func (s *Service) SendPush(data PushData) error

func (*Service) SingleLoginHandler

func (s *Service) SingleLoginHandler(c *gin.Context)

SingleLoginHandler is used for one-time authentications. It checks a signed entered otp keys against the user's credentials (user's stored public key)

NOTES This function only allows one-time authentication VIA the same device that the user originally has signed up with.

func (*Service) Status

func (s *Service) Status(c *gin.Context)

Status get transactions status from ebs

func (*Service) ToDatabasename

func (s *Service) ToDatabasename(url string) string

func (*Service) TransactionStatus

func (s *Service) TransactionStatus(c *gin.Context)

TransactionStatus queries EBS to get the status of the transaction

func (*Service) VerifyFirebase

func (s *Service) VerifyFirebase(c *gin.Context)

VerifyFirebase used to confirm that the user's token is valid

func (*Service) VerifyOTP added in v0.3.0

func (s *Service) VerifyOTP(c *gin.Context)

func (*Service) WorkingKey

func (s *Service) WorkingKey(c *gin.Context)

WorkingKey get ebs working key for encrypting ipin for consumer transactions

Notes

Bugs

  • Encrypt password here

Jump to

Keyboard shortcuts

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