2019-10-10 18:12:23 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package stripecoinpayments
|
|
|
|
|
|
|
|
import (
|
2019-10-15 19:05:45 +01:00
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
2019-10-15 12:23:54 +01:00
|
|
|
"github.com/stripe/stripe-go/client"
|
2019-10-10 18:12:23 +01:00
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"gopkg.in/spacemonkeygo/monkit.v2"
|
2019-10-15 12:23:54 +01:00
|
|
|
|
|
|
|
"storj.io/storj/satellite/payments"
|
2019-10-17 15:04:50 +01:00
|
|
|
"storj.io/storj/satellite/payments/coinpayments"
|
2019-10-10 18:12:23 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var mon = monkit.Package()
|
|
|
|
|
2019-10-17 15:04:50 +01:00
|
|
|
// Error defines stripecoinpayments service error.
|
|
|
|
var Error = errs.Class("stripecoinpayments service error")
|
2019-10-10 18:12:23 +01:00
|
|
|
|
2019-10-17 15:04:50 +01:00
|
|
|
// Config stores needed information for payment service initialization.
|
2019-10-15 12:23:54 +01:00
|
|
|
type Config struct {
|
2019-10-17 15:04:50 +01:00
|
|
|
StripeSecretKey string
|
|
|
|
CoinpaymentsPublicKey string
|
|
|
|
CoinpaymentsPrivateKey string
|
2019-10-10 18:12:23 +01:00
|
|
|
}
|
|
|
|
|
2019-10-15 12:23:54 +01:00
|
|
|
// Service is an implementation for payment service via Stripe and Coinpayments.
|
|
|
|
type Service struct {
|
2019-10-17 15:04:50 +01:00
|
|
|
customers CustomersDB
|
|
|
|
transactionsDB TransactionsDB
|
|
|
|
stripeClient *client.API
|
|
|
|
coinpayments coinpayments.Client
|
2019-10-10 18:12:23 +01:00
|
|
|
}
|
|
|
|
|
2019-10-15 12:23:54 +01:00
|
|
|
// NewService creates a Service instance.
|
2019-10-17 15:04:50 +01:00
|
|
|
func NewService(config Config, customers CustomersDB, transactionsDB TransactionsDB) *Service {
|
|
|
|
stripeClient := client.New(config.StripeSecretKey, nil)
|
|
|
|
|
|
|
|
coinpaymentsClient := coinpayments.NewClient(
|
|
|
|
coinpayments.Credentials{
|
|
|
|
PublicKey: config.CoinpaymentsPublicKey,
|
|
|
|
PrivateKey: config.CoinpaymentsPrivateKey,
|
|
|
|
},
|
|
|
|
)
|
2019-10-10 18:12:23 +01:00
|
|
|
|
2019-10-15 12:23:54 +01:00
|
|
|
return &Service{
|
2019-10-17 15:04:50 +01:00
|
|
|
customers: customers,
|
|
|
|
transactionsDB: transactionsDB,
|
|
|
|
stripeClient: stripeClient,
|
|
|
|
coinpayments: *coinpaymentsClient,
|
2019-10-10 18:12:23 +01:00
|
|
|
}
|
|
|
|
}
|
2019-10-11 16:00:35 +01:00
|
|
|
|
2019-10-15 12:23:54 +01:00
|
|
|
// Accounts exposes all needed functionality to manage payment accounts.
|
2019-10-15 19:05:45 +01:00
|
|
|
func (service *Service) Accounts(userID uuid.UUID) payments.Accounts {
|
2019-10-15 12:23:54 +01:00
|
|
|
return &accounts{service: service}
|
2019-10-11 16:00:35 +01:00
|
|
|
}
|