satisgo

package module
v0.0.0-...-e42c7a9 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2017 License: MIT Imports: 16 Imported by: 0

README

Satisgo SDK

Go Report Card Build Status Docs License

This is an SDK for the Satispay Business API.

It's not production ready but all the functions are there.

Obviously since every call has go to the the Satispay endpoint, making an https request, this cannot be done syncronously with you page loading, but it can be done asyncrounous and nothing bad can happen.

Roadmap

  • Strengthen security with http.Transport & tls.Config structs. The fundation work has been done, PR welcomed
  • Shorten methods name
  • Make it thread safe
  • Create middleware for popular web-framework (gin/echo/martini...)

Installation

go get github.com/drymonsoon/satisgo

Usage

  • examples are coming

Documentation

Warning

This library is licenced MIT: everyone can use, improve it, change it and make a lot of money on it. You cannot sue me if something goes wrong, you take all the responsability using this.

Documentation

Overview

Package satisgo helps people make more money having less commissions. Easy of use and automatic deposits to your bank account once the ammount is over the setted limit.

Index

Constants

View Source
const (
	//Required represent a status waiting for a payment
	Required = "REQUIRED"
	//Success represent "payment successfull"
	Success = "SUCCESS"
	//Failure represent payment Failure
	Failure = "FAILURE"
	//ErrDeclined represent a cancellation from the user
	ErrDeclined = "DECLINED_BY_PAYER"
	//ErrFalseRequest represent a cancellation by the wrong user
	ErrFalseRequest = "DECLINED_BY_PAYER_NOT_REQUIRED"
	//ErrNewer is the cancellation of the charge because the user received a new one
	ErrNewer = "CANCEL_BY_NEW_CHARGE"
	//ErrInternal represent a failure from the server
	ErrInternal = "INTERNAL_FAILURE"
	//ErrExpired the user took to long to respond to the charge request
	ErrExpired = "EXPIRED"
)
View Source
const (
	//ReasonDuplicate happens when two of the same charge appears
	ReasonDuplicate = "DUPLICATE"
	//ReasonFraud happens when someone else creates and approves a transaction for a user.
	ReasonFraud = "FRAUDULENT"
	//ReasonCustomerRequest if the customer requested a refund (if allowed by company policy)
	ReasonCustomerRequest = "REQUESTED_BY_CUSTOMER"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Ammount

type Ammount struct {
	TotalCharge int    `json:"total_charge_amount_unit"`
	TotalRefund int    `json:"total_refund_amount_unit"`
	Currency    string `json:"currency"`
}

Ammount is used to calculate total "sales" and refunds

type Charge

type Charge struct {
	//ID is the unique charge_id
	ID string `json:"id,omitempty"`
	//Description is the about the charge
	Description string `json:"description,omitempty"`
	//for now only "EUR" is supported
	Currency string `json:"currency,omitempty"`
	//Amount is expressed in EuroCents
	Amount uint64 `json:"amount,omitempty"`
	//Status can have one of 3 states: REQUIRED,SUCCESS,FAILURE
	Status string `json:"status,omitempty"`
	//StatusDetails is helpfull identifing the problem when FAILURE is display as status
	StatusDetails string `json:"status_detail,omitempty"`
	//UserID is the user unique indentifier
	UserID string `json:"user_id,omitempty"`
	//UserShortName is given by webButton
	UserShortName string `json:"user_short_name,omitempty"`
	//Metadata has max 20 fields(key value storage for charges)
	Metadata map[string]string `json:"metadata,omitempty,omitempty"`
	//Return a string of "true" or "false"
	Paid bool `json:"paid,omitempty"`
	//ChargeDate is the date in which the payment has been made
	ChargeDate string `json:"charge_date,omitempty"`
	//Refund is the ammount of the charge that has gone in a Refund
	Refund uint64 `json:"refund_amount,omitempty"`
	//EmailOnSuccess takes "true" or "false" and send an email after a payment has occurred (true by default with this library)
	EmailOnSuccess bool `json:"required_success_email,omitempty"`
	//ExpireIn represent the number of seconds the user has to approve the payment before it expires
	ExpireIn int `json:"expire_in,omitempty"`
	//Expire date is the rielaboration of the ExpireIN from the server
	ExpireDate string `json:"expire_date,omitempty"`
	//Is given to get notified when a "status" change in a charge
	CallbackURL string `json:"callback_url,omitempty"`
}

Charge is the type that handles charges for the user

func (*Charge) CancelCharge

func (c *Charge) CancelCharge(p *Satis) error

CancelCharge cancel a charge not yet approved by client

func (*Charge) CreateCharge

func (c *Charge) CreateCharge(p *Satis) error

CreateCharge is the function that makes the call to Satispay API

func (*Charge) NewRefund

func (c *Charge) NewRefund() (*Refund, error)

NewRefund generates a refund based on the given charge

func (*Charge) NewRefundWithAmount

func (c *Charge) NewRefundWithAmount(a float64) (*Refund, error)

NewRefundWithAmount generates a refund based on the given charge and the ammount supplied

func (*Charge) SetAmmount

func (c *Charge) SetAmmount(a float64) error

SetAmmount helps inserting a description into the charge THIS IS MANDATORY

func (*Charge) SetCallbackURL

func (c *Charge) SetCallbackURL(s string) error

SetCallbackURL is used to change the default 15 minutes expiration time for approving a charge THIS IS NOT MANDATORY

func (*Charge) SetDescription

func (c *Charge) SetDescription(s string) error

SetDescription helps inserting a description into the charge THIS IS NOT MANDATORY BUT HIGHLY SUGGESTED

func (*Charge) SetExpiration

func (c *Charge) SetExpiration(d time.Duration) error

SetExpiration is used to change the default 15 minutes expiration time for approving a charge THIS IS NOT MANDATORY

func (*Charge) SetMetadata

func (c *Charge) SetMetadata(key, value string) error

SetMetadata is used to add metadata to a charge without making any mess around THere are some limits: max 20pairs, key length max 45 chars, value max 500 chars THIS IS NOT MANDATORY

func (*Charge) UpdateChargeDescription

func (c *Charge) UpdateChargeDescription(p *Satis) error

UpdateChargeDescription returns a modified Charge provided one

func (*Charge) UpdateChargeMetadata

func (c *Charge) UpdateChargeMetadata(p *Satis) error

UpdateChargeMetadata returns a modified Charge provided one

type Refund

type Refund struct {
	//ID is the unique charge_id
	ID string `json:"id,omitempty"`
	//ChargeID is the charge unique indentifier
	ChargeID string `json:"charge_id,omitempty"`
	//Description is the about the charge
	Description string `json:"description,omitempty"`
	//for now only "EUR" is supported
	Currency string `json:"currency,omitempty"`
	//Amount is expressed in EuroCents
	Amount uint64 `json:"amount,omitempty"`
	//Metadata has max 20 fields(key value storage for charges)
	Metadata map[string]string `json:"metadata,omitempty"`
	//Created is the time in UnixMilli of the creation of the refund
	Created string `json:"reason,omitempty"`
	//Reason is the reason a refund occurred
	Reason string `json:"reason,omitempty"`
}

Refund is the type that handles charges for the user

func (*Refund) CreateRefund

func (r *Refund) CreateRefund(p *Satis) error

CreateRefund is the function that makes the call to Satispay API to request a refund with the given parameters

func (*Refund) SetAmmount

func (r *Refund) SetAmmount(a float64) error

SetAmmount helps inserting a description into the refund THIS IS MANDATORY

func (*Refund) SetDescription

func (r *Refund) SetDescription(s string) error

SetDescription helps inserting a description into the refund THIS IS NOT MANDATORY BUT HIGHLY SUGGESTED

func (*Refund) SetMetadata

func (r *Refund) SetMetadata(key, value string) error

SetMetadata is used to add metadata to a refund without making any mess around THere are some limits: max 20pairs, key length max 45 chars, value max 500 chars THIS IS NOT MANDATORY

func (*Refund) SetReason

func (r *Refund) SetReason(reason string) error

SetReason helps inserting a reason into the refund instance THIS IS NOT MANDATORY BUT HIGHLY SUGGESTED Only few reasons are allowed (use of package costants is suggested)

func (*Refund) UpdateRefundMetadata

func (r *Refund) UpdateRefundMetadata(p *Satis) error

UpdateRefundMetadata returns a modified Refund provided one

type Satis

type Satis struct {
	// contains filtered or unexported fields
}

Satis is the base unit for a payment/action with the satispay API

func New

func New(bearer, env string) (*Satis, error)

New is the generator for a basic interaction with the API

func (*Satis) AmmountSpecificDate

func (p *Satis) AmmountSpecificDate(year, month, day int) (*Ammount, error)

AmmountSpecificDate return the total ammount of charges for the past week

func (*Satis) AmmountSpecificYear

func (p *Satis) AmmountSpecificYear(year int) (*Ammount, error)

AmmountSpecificYear is cool for accountability

func (*Satis) AmmountThisMonth

func (p *Satis) AmmountThisMonth() (*Ammount, error)

AmmountThisMonth is cool for accountability

func (*Satis) AmmountThisWeek

func (p *Satis) AmmountThisWeek() (*Ammount, error)

AmmountThisWeek return the total ammount of charges for the past week

func (*Satis) AmmountThisYear

func (p *Satis) AmmountThisYear() (*Ammount, error)

AmmountThisYear is cool for accountability

func (*Satis) AmmountToday

func (p *Satis) AmmountToday() (*Ammount, error)

AmmountToday return the total ammount of charges for the past week

func (*Satis) AmmountYesterday

func (p *Satis) AmmountYesterday() (*Ammount, error)

AmmountYesterday return the total ammount of charges for the past week

func (*Satis) GetAllCharges

func (p *Satis) GetAllCharges() (*[]Charge, error)

GetAllCharges returns all charges from the beginning

func (*Satis) GetAllRefunds

func (p *Satis) GetAllRefunds() (*[]Refund, error)

GetAllRefunds returns all charges from the beginning

func (*Satis) GetAllUsers

func (p *Satis) GetAllUsers() (*[]User, error)

GetAllUsers returns all charges from the beginning

func (*Satis) GetCharge

func (p *Satis) GetCharge(id string) (*Charge, error)

GetCharge returns a charge provided a charge_id

func (*Satis) GetRefund

func (p *Satis) GetRefund(id string) (*Refund, error)

GetRefund returns a refund provided a refund_id

func (*Satis) GetRefundFromChargeID

func (p *Satis) GetRefundFromChargeID(chargeID string) (*[]Refund, error)

GetRefundFromChargeID returns all charges from the beginning

func (*Satis) GetRefundSinceChargeID

func (p *Satis) GetRefundSinceChargeID(chargeID string) (*[]Refund, error)

GetRefundSinceChargeID returns all charges from the beginning

func (*Satis) UserFromID

func (p *Satis) UserFromID(id string) (*User, error)

UserFromID is the way to get a phone number with an id

func (*Satis) UserFromPhone

func (p *Satis) UserFromPhone(phone string) (*User, error)

UserFromPhone is the way to get an identifier with a phone number

func (*Satis) Verify

func (p *Satis) Verify() error

Verify is used to make sure the token is correct

type User

type User struct {
	ID    string `json:"id"`
	Phone string `json:"phone_number"`
}

User is the parsed object from a call to user list

func (*User) NewCharge

func (u *User) NewCharge() (*Charge, error)

NewCharge generates a charge based on the obtained user

Jump to

Keyboard shortcuts

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