README
¶
MANGOPAY Go SDK
Don't use this SDK in Production mode, this current SDK is not fully tested.
MangopaySDK is a Go client library to work with Mangopay REST API.
Compatibility Notes
- Since v2.1 of this SDK, you must be using at least v2.01 of the API (more information about the changes required)
- If you experience problems with authentification and/or the temporary token file following an SDK update
(particuarly updating to v2.0 of the SDK), you may need to just delete your temporary file
(that you specify with
api.TemporaryFolder
) - which allows it to be regenerated correctly the next time it's needed
Requirements
To use this SDK, you will need (as a minimum):
- Golang v1.13.5 (at least 1.13 is recommended)
Installation
You can use Mangopay SDK library as a dependency in your project with
go get -u github.com/58-facettes/mangopay-go-sdk
(which is the preferred technique). Follow [these installation instructions]
License
MangopaySDK is distributed under MIT license, see the LICENSE file.
Unit Tests
This project is not yet fully test. To run test just go into the root directory and run the following command.
$ make test
Contacts & Bugs
Report bugs or suggest features using issue tracker on GitHub.
Account creation
You can get yourself a free sandbox account or sign up for a production account (note that validation of your production account can take a few days, so think about doing it in advance of when you actually want to go live).
Configuration
Using the credential info from the signup process above, you should then set client-id
to your Mangopay ClientId and client-password
to your Mangopay APIKey.
You also need to set a folder path in api.TemporaryFolder
that SDK needs
to store temporary files. This path should be outside your www folder.
It could be /tmp/
or /var/tmp/
or any other location that Go can write to.
You must use different folders for your sandbox and production environments.
BaseUrl
is set to sandbox environment by default. To enable production
environment, set mangopay.Mode
to mangopay.Production
.
package main
import(
"github.com/58-facettes/magopay-go-sdk"
)
func main() {
// mangopay.Mode = mangopay.Production // uncomment this to use the production environment
api := mangopay.NewWithBasicAuth("your-client-id","your-client-password")
api.TempPath = "/some/path/"
// api.ResponseTimeout = 20 // The cURL response timeout in seconds (its 30 by default)
// api.ConnectionTimeout = 60;//The cURL connection timeout in seconds (its 80 by default)
// api.CertificatesFilePath = "" //Absolute path to file holding one or more certificates
// to verify the peer with (if empty, there won't be any verification of the peer's certificate).
users, err = api.Users.GetAll()
if err != nil {
log.Fatal(err)
}
log.Print(users)
}
Sample usage
package main
import (
"log"
"github.com/58-facettes/mangopay-go-sdk"
"github.com/58-facettes/mangopay-go-sdk/model"
)
func main() {
// mangopay.Mode = mangopay.Production // uncomment this to use the production environment.
api := mangopay.NewWithBasicAuth("client-id", "client-pass")
john, err := api.Users.View("someID")
if err != nil {
log.Fatal(err)
}
log.Print(john)
// change and update some of his data.
_, err = api.Users.UpdateNaturalUser("someID", &model.NaturalUserUpdate{
FirstName: " - CHANGED",
})
log.Print(err)
// get all users (with pagination)
pagination := model.NewPagination(0, 8)
users, err := api.Users.List(pagination)
if err != nil {
log.Fatal(err)
}
log.Print(users)
// get his bank accounts
pagination = model.NewPagination(2, 10)
bankAccount, err := api.BankAccounts.ViewFromUser(john.ID, pagination)
if err != nil {
log.Fatal(err)
}
log.Print(bankAccount)
}
Sample usage with gin.
You can integrate Mangopay features in a Service in your gin project.
main.go
:
package main
import (
"log"
"net/http"
"github.com/58-facettes/mangopay-go-sdk"
"github.com/gin-gonic/gin"
)
var api = mangopay.NewWithBasicAuth("client-id", "client-password")
func main() {
router := gin.Default()
router.GET("/users/:userID", HandlerUser)
router.Run(":8080")
}
func HandlerUser(ctx *gin.Context) {
jhon, err := api.Users.View(ctx.Param("userID"))
if err != nil {
log.Println("error is ", err.Error())
ctx.AbortWithError(400, err)
return
}
ctx.JSON(http.StatusOK, jhon)
}
And run it into the terminal.
$ go run main.go
Logging
MangoPay uses the a Logger interface. You can provide your own logger to the API. Here is a sample showing Monolog integration :
type MyLogger struct{}
func (ml *MyLogger)Debug(args ...interface{})
func (ml *MyLogger)Debugf(template string, args ...interface{})
func (ml *MyLogger)Error(args ...interface{})
func (ml *MyLogger)Errorf(template string, args ...interface{})
func (ml *MyLogger)Fatal(args ...interface{})
func (ml *MyLogger)Fatalf(template string, args ...interface{})
func (ml *MyLogger)Warnf(template string, args ...interface{})
api.Logger = &MyLogger{};
Verifying rate limits status
According to API docs (https://docs.mangopay.com/guide/rate-limiting), MangoPay is providing a way of verifying how many API calls were made, how many are left and when the counter will be reset. So there are 4 groups of rate limits available:
- Last 15 minutes:
- Last 30 minutes
- Last 60 minutes
- Last 24 hours
This information is available from the MangoPayApi instance, like in the following example:
package main
import (
"github.com/58-facettes/mangopay-go-sdk"
)
func main() {
api := mangopay.NewWithBasicAuth("your-client-id","your-client-password")
log.Println(api.RateLimits(model.RateLimit15Minutes))
}
Documentation
¶
Overview ¶
Package Mangopay provides services to communicate with the official API.
A basic usage would be to create a Basic Auth connexion.
api := mangopay.NewWithBasicAuth(cliendID, clientPassword) cli, _ := api.Client.View() log.Print(cli) // this will display your current Client information.
Index ¶
Examples ¶
Constants ¶
const ( // APIVersion is the current API version in the URI calls. APIVersion = "v2.01" // ModeTest is for using the API sandbox. ModeTest = "test" // ModeProduction is for the API production. ModeProduction = "production" )
Variables ¶
var ( // Mode is the mode of the SDK calls by defaults this is set to test mode. Mode = ModeTest // Logger is the default internal logging tool that is used. // This can be replaced by another logging tool of your choice like Zap or Logrus. Logger log.Logger = log.DefaultLogger )
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct { // List of all avalable services. Clients *service.Clients ClientWallets *service.ClientWallets Users *service.Users UserEmoney *service.UserEmoneys Wallets *service.Wallets Cards *service.Cards PayIns *service.PayIns Transferts *service.Transferts BankAccounts *service.BankAccounts PayOuts *service.PayOuts KYCs *service.KYCs Stats *service.Stats UBOs *service.UBOs Mandates *service.Mandates Hooks *service.Hooks Events *service.Events Transactions *service.Transactions PreAuthorizations *service.PreAuthorizations Refunds *service.Refunds Disputes *service.Disputes DisputeDocuments *service.DisputeDocunents Repudiations *service.Repudiations SettlementTransfers *service.SettlementTranfers BankingAliases *service.BankingAliases SSOS *service.SSOS PermissionGroups *service.PermissionGoups Reports *service.Reports Idempotencies *service.Idempotencies // contains filtered or unexported fields }
API holds all the services for calling Mongopay API.
func NewWithBasicAuth ¶
NewWithBasicAuth sends a new Mangonpay client with Basic Auth.
Example ¶
Output:
func NewWithOAuth ¶
NewWithOAuth is used for an oauth token connexion.