"github.com/Paypi/paypi-go/paypi"
paypi.Key = "<API_SECRET_KEY>"
func handleRequest(w http.ResponseWriter, r *http.Request) {
// Check if a user's token is valid
user, err := paypi.Authenticate(r.Header.Get("Authorization"))
http.Error(w, "User token is unauthorized", http.StatusUnauthorized)
// Carry out PDF conversion and calculate usage...
pdfSize := 1 // PDF size in MB
charge, err := user.MakeCharge(paypi.MakeChargeInput{
ChargeIdentifier: "cid-AAAAAA",
http.Error(w, err.Message, http.StatusInternalServerError)
charge, err := user.MakeCharge(paypi.MakeChargeInput{
ChargeIdentifier: "cid-BBBBBB",
http.Error(w, err.Message, http.StatusInternalServerError)
fmt.Fprintf(w, "Returning your JPG")