-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 61a6d15
Showing
12 changed files
with
418 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
on: [push, pull_request] | ||
name: Test | ||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
go-version: [1.16.x] | ||
os: [ubuntu-latest] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Test | ||
run: go mod tidy && go test ./... -coverprofile=coverage.txt -covermode=atomic | ||
|
||
- name: Upload coverage report | ||
uses: codecov/[email protected] | ||
with: | ||
token: 46826cd9-0b61-4f05-b564-9f9b335c6e7f | ||
file: ./coverage.txt | ||
flags: unittests | ||
name: codecov-umbrella |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
examples/config.json | ||
|
||
go.sum | ||
|
||
cover.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Vinícius Boscardin | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<p align="center"> | ||
<h1 align="center">Zenvia API - Golang SDK</h1> | ||
<p align="center">Zenvia API (2.0) </p> | ||
<p align="center"> | ||
<a href="https://pkg.go.dev/github.com/booscaaa/zenvia-go-sdk"><img alt="Reference" src="https://img.shields.io/badge/go-reference-purple?style=for-the-badge"></a> | ||
<a href="https://github.com/booscaaa/zenvia-go-sdk/releases/latest"><img alt="Release" src="https://img.shields.io/github/v/release/booscaaa/zenvia-go-sdk.svg?style=for-the-badge"></a> | ||
<a href="/LICENSE"><img alt="Software License" src="https://img.shields.io/badge/license-MIT-red.svg?style=for-the-badge"></a> | ||
<a href="https://github.com/booscaaa/zenvia-go-sdk/actions/workflows/test.yaml"><img alt="Test status" src="https://img.shields.io/github/workflow/status/booscaaa/zenvia-go-sdk/Test?label=TESTS&style=for-the-badge"></a> | ||
<a href="https://codecov.io/gh/booscaaa/zenvia-go-sdk"><img alt="Coverage" src="https://img.shields.io/codecov/c/github/booscaaa/zenvia-go-sdk/master.svg?style=for-the-badge"></a> | ||
</p> | ||
</p> | ||
|
||
<br> | ||
|
||
## Why? | ||
|
||
This project is part of my personal portfolio, so, I'll be happy if you could provide me any feedback about the project, code, structure or anything that you can report that could make me a better developer! | ||
|
||
Email-me: [email protected] | ||
|
||
Connect with me at [LinkedIn](https://www.linkedin.com/in/booscaaa/). | ||
|
||
<br> | ||
|
||
## Functionalities | ||
|
||
- Get authentication token | ||
- Create tokenized card | ||
- Get plans for signatures | ||
- Get plan by ID | ||
- Create plan | ||
- Disable plan by ID | ||
- Enable plan by ID | ||
|
||
<br> | ||
|
||
## Getting Started | ||
|
||
### Prerequisites | ||
|
||
To run this project in the development mode, you'll need to have a basic environment to run: | ||
|
||
- A Golang SDK, that can be found [here](https://golang.org/). | ||
|
||
<br> | ||
|
||
### Installing | ||
|
||
```bash | ||
$ go get github.com/booscaaa/zenvia-go-sdk | ||
``` | ||
|
||
<br> | ||
|
||
### Create a config.json file inside your project like this | ||
|
||
**The access api_token can be found into Zenvia account** | ||
|
||
```json | ||
{ | ||
"zenvia": { | ||
"api_token": "api token" | ||
} | ||
} | ||
``` | ||
|
||
<br> | ||
<br> | ||
|
||
### Create main.go file | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/booscaaa/zenvia-go-sdk/zenvia" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func init() { | ||
viper.SetConfigFile(`config.json`) | ||
err := viper.ReadInConfig() | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func main() { | ||
// Get configuration variavables | ||
authToken := viper.GetString("zenvia.auth_token") | ||
|
||
// Configure Sandbox access into Zenvia api | ||
// From and To with this format: PREFIX DDD NUMBER WITHOUT MASK | ||
zenviaAccess := zenvia.ZenviaConfig(). | ||
ApiToken(authToken). | ||
From("5554999999999"). | ||
To("5554999999999"). | ||
Sandbox() | ||
|
||
zenviaSdk := zenvia.Instance(zenviaAccess) | ||
|
||
zenviaSdk.SendSMS("Message") | ||
|
||
//see more examples into examples folder | ||
} | ||
``` | ||
|
||
# Running local | ||
|
||
```bash | ||
go run main.go | ||
``` | ||
|
||
<br> | ||
<br> | ||
<br> | ||
|
||
## Api application built With | ||
|
||
- [Viper](https://github.com/spf13/viper) | ||
|
||
<br> | ||
<br> | ||
<br> | ||
|
||
## Contributing | ||
|
||
You can send how many PR's do you want, I'll be glad to analyze and accept them! And if you have any question about the project... | ||
|
||
Email-me: [email protected] | ||
|
||
Connect with me at [LinkedIn](https://www.linkedin.com/in/booscaaa/) | ||
|
||
Thank you! | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/booscaaa/zenvia-go-sdk/blob/master/LICENSE) file for details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"zenvia": { | ||
"api_token": "api token in zenvia platform" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
|
||
<script type="text/javascript" src="https://sandbox.boletobancario.com/boletofacil/wro/direct-checkout.min.js"></script> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
|
||
<script type="text/javascript"> | ||
var checkout = new DirectCheckout('FDC00232FBEF19EC6F355BDCDCBC3C6A6EC8616C5CC086ACA1A9AA75C58C484E', false); | ||
/* Em sandbox utilizar o construtor new DirectCheckout('PUBLIC_TOKEN', false); */ | ||
|
||
|
||
var cardData = { | ||
cardNumber: '5362682003164890', | ||
holderName: 'Teste', | ||
securityCode: '158', | ||
expirationMonth: '10', | ||
expirationYear: '2026' | ||
}; | ||
|
||
|
||
checkout.getCardHash(cardData, function(cardHash) { | ||
console.log(cardHash); | ||
}, function(error) { | ||
console.log(error); | ||
/* Erro - A variável error conterá o erro ocorrido ao obter o hash */ | ||
}); | ||
|
||
|
||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/booscaaa/zenvia-go-sdk/zenvia" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func init() { | ||
viper.SetConfigFile(`config.json`) | ||
err := viper.ReadInConfig() | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func main() { | ||
// Get configuration variavables | ||
authToken := viper.GetString("zenvia.auth_token") | ||
|
||
// Configure Sandbox access into Zenvia api | ||
// From and To with this format: PREFIX DDD NUMBER WITHOUT MASK | ||
zenviaAccess := zenvia.ZenviaConfig(). | ||
ApiToken(authToken). | ||
From("5554999999999"). | ||
To("5554999999999"). | ||
Sandbox() | ||
|
||
zenviaSdk := zenvia.Instance(zenviaAccess) | ||
|
||
zenviaSdk.SendSMS("Message") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/booscaaa/zenvia-go-sdk | ||
|
||
go 1.17 | ||
|
||
require github.com/spf13/viper v1.8.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package zenvia | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
const ( | ||
PRODUCTION = "https://api.zenvia.com" | ||
SANDBOX = "https://TODO" | ||
) | ||
|
||
var ( | ||
Client HTTPClient | ||
) | ||
|
||
type HTTPClient interface { | ||
Do(req *http.Request) (*http.Response, error) | ||
} | ||
|
||
type ZenviaAccess struct { | ||
api string | ||
from string | ||
to string | ||
apiToken string | ||
} | ||
|
||
func ZenviaConfig() ZenviaAccess { | ||
return ZenviaAccess{ | ||
api: PRODUCTION, | ||
} | ||
} | ||
|
||
func (zenviaAccess ZenviaAccess) ApiToken(apiToken string) ZenviaAccess { | ||
zenviaAccess.apiToken = apiToken | ||
|
||
return zenviaAccess | ||
} | ||
|
||
func (zenviaAccess ZenviaAccess) From(from string) ZenviaAccess { | ||
zenviaAccess.from = from | ||
|
||
return zenviaAccess | ||
} | ||
|
||
func (zenviaAccess ZenviaAccess) To(to string) ZenviaAccess { | ||
zenviaAccess.to = to | ||
|
||
return zenviaAccess | ||
} | ||
|
||
func (zenviaAccess ZenviaAccess) Sandbox() ZenviaAccess { | ||
zenviaAccess.api = SANDBOX | ||
|
||
return zenviaAccess | ||
} | ||
|
||
type ZenviaAccessRepository interface { | ||
SendSMS(message string) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package model | ||
|
||
type SMSContent struct { | ||
Type string `json:"type"` | ||
Text string `json:"text"` | ||
} | ||
|
||
func CreateSMSContent(tx string) SMSContent { | ||
return SMSContent{ | ||
Type: "text", | ||
Text: tx, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package model | ||
|
||
type SMSPatyload struct { | ||
From string `json:"from"` | ||
To string `json:"to"` | ||
Contents []SMSContent `json:"contents"` | ||
} | ||
|
||
func CreateSingleSMSPayload(from string, to string, content SMSContent) SMSPatyload { | ||
return SMSPatyload{ | ||
From: from, | ||
To: to, | ||
Contents: []SMSContent{ | ||
content, | ||
}, | ||
} | ||
} |
Oops, something went wrong.