Commit f8e27c1c authored by Morbi's avatar Morbi

fetch one invoice

parent 483baf3f
bitpay
config.json
{
"API": {
"BaseURL": "http://localhost:9991",
"PathPrefix": "v1/",
"Bind": ":9991",
"SwaggerAPIPath": "/apidocs.json",
"SwaggerPath": "/apidocs/",
"SwaggerFilePath": "/home/ubuntu/swagger-ui/dist",
"ImageFilePath": "/home/ubuntu/sangha_images"
},
"Connections": {
"PostgreSQL": {
"Host": "localhost",
"DbName": "sangha",
"User": "user",
"Password": "password",
"Port": 5432,
"SslMode": "disable"
},
"AMQP": {
"Host": "localhost",
"User": "user",
"Password": "password",
"Port": 5672,
"Broker": "rabbit",
"Queue": "payments"
}
},
"PaymentProviders": {
"Bitpay": {
"Pem": "-----BEGIN EC PRIVATE KEY-----\nYOUR VERY PRIVATE KEY\n-----END EC PRIVATE KEY-----",
"URL": "https://test.bitpay.com"
}
},
"Web": {
"BaseURL": "http://localhost:4200/"
}
}
package main
import (
"fmt"
bitpay "github.com/bitpay/bitpay-go/client"
ku "github.com/bitpay/bitpay-go/key_utils"
"github.com/spf13/cobra"
"gitlab.techcultivation.org/sangha/sangha/config"
)
var (
fetchCmd = &cobra.Command{
Use: "fetch",
Short: "fetch new payments",
Long: `The fetch command retrieves all new incoming payments from bitpay`,
RunE: func(cmd *cobra.Command, args []string) error {
return executeFetch()
},
}
)
func executeFetch() error {
client := bitpay.Client{
Pem: config.Settings.PaymentProviders.Bitpay.Pem,
ClientId: ku.GenerateSinFromPem(config.Settings.PaymentProviders.Bitpay.Pem),
ApiUri: config.Settings.PaymentProviders.Bitpay.URL,
}
invoice, err := client.GetInvoice("invoice_id")
if err != nil {
panic(err)
}
fmt.Printf("your invoice %+v", invoice)
return nil
}
func init() {
RootCmd.AddCommand(fetchCmd)
}
package main
import (
"os"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"gitlab.techcultivation.org/sangha/mq"
"gitlab.techcultivation.org/sangha/sangha/config"
"gitlab.techcultivation.org/sangha/sangha/db"
"gitlab.techcultivation.org/sangha/sangha/logger"
)
var (
// RootCmd is the core command used for cli-arg parsing
RootCmd = &cobra.Command{
Use: "bitpay",
Short: "bitpay processor",
Long: "bitpay processor is the bitpay processor of the sangha framework\n" +
"Complete documentation is available at https://gitlab.techcultivation.org/sangha/sangha",
SilenceErrors: false,
SilenceUsage: true,
}
)
func main() {
var configFile, logLevelStr string
RootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "config.json", "use this config file (JSON format)")
RootCmd.PersistentFlags().StringVarP(&logLevelStr, "loglevel", "l", "info", "log level")
logLevel, err := log.ParseLevel(logLevelStr)
if err != nil {
log.Fatal(err)
}
log.SetLevel(logLevel)
config.ParseSettings(configFile)
logger.SetupLogger(config.Settings.Connections.Logger.Protocol,
config.Settings.Connections.Logger.Address,
"bitpay-processor")
log.Infoln("Starting payment bitpay processor")
db.SetupPostgres(config.Settings.Connections.PostgreSQL)
mq.SetupAMQP(config.Settings.Connections.AMQP)
if err := RootCmd.Execute(); err != nil {
os.Exit(-1)
}
}
package main
import (
"fmt"
bitpay "github.com/bitpay/bitpay-go/client"
ku "github.com/bitpay/bitpay-go/key_utils"
"gitlab.techcultivation.org/sangha/sangha/config"
"github.com/spf13/cobra"
)
var (
pairCmd = &cobra.Command{
Use: "pair",
Short: "pair client",
Long: `The pair command pairs the client keys with the bitpay api`,
RunE: func(cmd *cobra.Command, args []string) error {
return executePairing()
},
}
)
func executePairing() error {
bitpayPem := ku.GeneratePem()
bitpayID := ku.GenerateSinFromPem(bitpayPem)
client := bitpay.Client{
Pem: bitpayPem,
ApiUri: config.Settings.PaymentProviders.Bitpay.URL,
ClientId: bitpayID,
}
token, err := client.PairWithFacade("merchant")
if err != nil {
panic(err)
}
fmt.Printf("Your Client PEM, store safely:\n%s", bitpayPem)
fmt.Printf(
"Please approve %s/dashboard/merchant/api-tokens with pairing code %s",
config.Settings.PaymentProviders.Bitpay.URL,
token.PairingCode)
return nil
}
func init() {
RootCmd.AddCommand(pairCmd)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment