![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
github.com/jSierraB3991/now_payment_api
A Golang package for integrating with the NOW Payments API, providing functionality for creating and managing payments and invoices.
go get github.com/jSierraB3991/now_payment_api
To use the NOW Payment API service, you'll need to initialize it with your credentials and configuration:
import nowPaymentService "github.com/jSierraB3991/now_payment_api/infrastructure/now_payments_service"
// Initialize the service
service := nowPaymentService.InitiateService(
database, // Your database instance
"YOUR_API_KEY", // NOW Payments API key
"https://api.nowpayments.io/v1", // API base URL (or sandbox URL for testing)
"YOUR_USERNAME", // NOW Payments username
"YOUR_PASSWORD" // NOW Payments password
)
For sandbox testing, use: https://api-sandbox.nowpayments.io/v1
The package provides an interface for interacting with the NOW Payments API. Here's how to implement it in your service:
import nowpaymentsserviceinterface "github.com/jSierraB3991/now_payment_api/domain/now_payments_service_interface"
type YourService struct {
nowPaymentService nowpaymentsserviceinterface.NowPaymentServiceInterface
frontendUrl string
backendUrl string
}
func NewYourService(
nowPaymentService nowpaymentsserviceinterface.NowPaymentServiceInterface,
frontendUrl string,
backendUrl string,
) *YourService {
return &YourService{
nowPaymentService: nowPaymentService,
frontendUrl: frontendUrl,
backendUrl: backendUrl,
}
}
To create a payment invoice:
import "github.com/jSierraB3991/now_payment_api/domain/now_payments_request"
func (s *YourService) CreateInvoice(amountPrice float64, user User) (*nowpaymentsresponse.CreateInvoiceResponse, error) {
request := nowpaymentsrequest.CreateInvoiceRequest{
AmountPrice: amountPrice,
PriceCurrency: "USD",
OrderID: orderID,
OrderDescription: fmt.Sprintf("Payment of %v USD for %s", amountPrice, user.Email),
SuccessURL: s.frontendUrl + "/success",
CancelURL: s.frontendUrl + "/fail",
IpnCallbackURL: s.backendUrl + "/public/now_payments/ipn",
}
return s.nowPaymentService.CreateInvoice(request, user.ID)
}
The NowPaymentServiceInterface
provides the following methods:
CreatePayment(req CreatePaymentRequest, userId uint) (*CreatePaymentResponse, error)
CreateInvoice(req CreateInvoiceRequest, userId uint) (*CreateInvoiceResponse, error)
GetInvoiceDataService(page, limit int, isAscendente bool, userId uint) ([]NowPaymentCreateInvoice, error)
GetPaymentStatus(paymentId string) (*GetPaymentStatusResponse, error)
GetInvoiceStatus(invoiceId string) (*GetPaymentStatusResponse, error)
All methods return an error as the second return value. Always check for errors when calling these methods:
response, err := service.CreateInvoice(request, userID)
if err != nil {
// Handle error appropriately
return nil, err
}
Contributions are welcome! Please feel free to submit a Pull Request.
Puedes encontrar una copia completa de la licencia en el archivo LICENSE en el repositorio de este proyecto.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.