Skip to content

Commit

Permalink
Merge pull request #1 from paylike/feature/implementation
Browse files Browse the repository at this point in the history
Initial implementation
  • Loading branch information
Roverr authored Mar 19, 2019
2 parents 1e2597c + a356679 commit 4c90b91
Show file tree
Hide file tree
Showing 7 changed files with 1,411 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

vendor
33 changes: 33 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[prune]
go-tests = true
unused-packages = true

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.3.0"
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test: ## Runs tests
go test ./...
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.DEFAULT_GOAL := help
141 changes: 139 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,139 @@
# go-api
Golang SDK for Paylike API
# Paylike client (Go)

Writing your own client? Checkout the raw [HTTP service](https://github.com/paylike/api-docs).

**Make sure to [subscribe to our mailling list](http://eepurl.com/bCGmg1) for
deprecation notices, API changes and new features**

[Godoc for the project](https://godoc.org/github.com/paylike/go-api)

## Getting an API key

An API key can be obtained by creating a merchant and adding an app through
our [dashboard](https://app.paylike.io). If your app's target audience is
third parties, please reach out and we will make your app's API key hidden.

## Install

```shell
dep ensure -add github.com/paylike/node-api
```

```golang
import paylike "github.com/paylike/go-api"

client := paylike.NewClient(os.Getenv("PAYLIKE_APP_KEY"))
```

## Methods

```golang
// change key for authentication
client.SetKey("key")

// this command is also chainable
app, err := client.SetKey("key").FetchApp()

// create an app (requires no authentication)
createdApp, err := client.CreateApp()

// create an app with a dedicated name
createdAppWithName, err := client.CreateAppWithName("myApplication")

// fetch current app (based on key)
app, err := client.FetchApp()

// list app's merchants with limit
merchants, err := client.FetchMerchants("appID", 10)

// create merchant
merchant, err := client.CreateMerchant(MerchantCreateDTO{
Test: true,
Currency: "HUF",
Email: TestEmail,
Website: TestSite,
Descriptor: "1234567897891234",
Company: &MerchantCompany{
Country: "HU",
},
})

// update merchant
err := client.UpdateMerchant(MerchantUpdateDTO{
Name: "Test",
Descriptor: "Test",
Email: "[email protected]",
})

// get merchant
fetchedMerchant, err := client.GetMerchant(merchant.ID)

// add users
data, err := client.InviteUserToMerchant(merchant.ID, "[email protected]")

// revoke users
err := client.RevokeUserFromMerchant(merchant.ID, users[0].ID)

// fetch users with limit
users, err := client.FetchUsersToMerchant(merchant.ID, 3)

// add app
err := client.AddAppToMerchant(merchant.ID, app.ID)

// revoke app
err := client.RevokeAppFromMerchant(merchant.ID, app.ID)

// fetch apps with limit
apps, err := client.FetchAppsToMerchant(merchant.ID, 2)

// fetch lines with limit
lines, err := client.FetchLinesToMerchant(merchant.ID, 1)

// create transaction
data, err := client.CreateTransaction(TestMerchant, TransactionDTO{
TransactionID: "560fd96b7973ff3d2362a78c",
Currency: "EUR",
Amount: 200,
Custom: map[string]interface{}{"source": "test"},
})

// fetch transactions with limit
transactions, err := client.ListTransactions(merchant.ID, 20)

// transaction capture
dto := TransactionTrailDTO{
Amount: 2,
Currency: "EUR",
Descriptor: "Testing",
}
transaction, err := client.CaptureTransaction(transaction.ID, dto)

// transaction refund
dto := TransactionTrailDTO{
Amount: 1,
Descriptor: "Testing Refund",
}
transaction, err := client.RefundTransaction(data.ID, dto)

// transaction void
dto := TransactionTrailDTO{
Amount: 1,
}
transaction, err := client.VoidTransaction(data.ID, dto)

// transaction find
transaction, err := client.FindTransaction(data.ID)

// card create
dto := CardDTO{
TransactionID: "560fd96b7973ff3d2362a78c",
}
data, err := client.CreateCard(TestMerchant, dto)

// card find
card, err := client.FetchCard(data.ID)
```

A webshop would typically need only `CaptureTransaction`, `RefundTransaction` and `VoidTransaction`. Some might
as well use `ListTransactions` and for recurring subscriptions
`CreateTransaction`.
Loading

0 comments on commit 4c90b91

Please sign in to comment.