Orders
Generate Order Invoice
Trigger generation of an order’s invoice.
Scopes: orders:read
POST
/
v1
/
orders
/
{id}
/
invoice
Go (SDK)
package main
import(
"context"
"os"
macropaygo "github.com/web3group/macropay-go-main"
"log"
)
func main() {
ctx := context.Background()
s := macropaygo.New(
macropaygo.WithSecurity(os.Getenv("MACROPAY_ACCESS_TOKEN")),
)
res, err := s.Orders.GenerateInvoice(ctx, "<value>")
if err != nil {
log.Fatal(err)
}
if res.Any != nil {
// handle response
}
}from macropay_sdk import Macropay
with Macropay(
access_token="<YOUR_BEARER_TOKEN_HERE>",
) as macropay:
res = macropay.orders.generate_invoice(id="<value>")
# Handle response
print(res)import { Macropay } from "@macropayments/sdk";
const macropay = new Macropay({
accessToken: process.env["MACROPAY_ACCESS_TOKEN"] ?? "",
});
async function run() {
const result = await macropay.orders.generateInvoice({
id: "<value>",
});
console.log(result);
}
run();declare(strict_types=1);
require 'vendor/autoload.php';
use Macropay;
$sdk = Macropay\Macropay::builder()
->setSecurity(
'<YOUR_BEARER_TOKEN_HERE>'
)
->build();
$response = $sdk->orders->generateInvoice(
id: '<value>'
);
if ($response->any !== null) {
// handle response
}curl --request POST \
--url https://api.macropay.ai/v1/orders/{id}/invoice \
--header 'Authorization: Bearer <token>'const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.macropay.ai/v1/orders/{id}/invoice', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://api.macropay.ai/v1/orders/{id}/invoice")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.macropay.ai/v1/orders/{id}/invoice")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"error": "MissingInvoiceBillingDetails",
"detail": "<string>"
}Once the invoice is generated, it’s permanent and cannot be modified.Make sure the billing details (name and address) are correct before generating the invoice. You can update them before generating the invoice by calling the
PATCH /v1/orders/{id} endpoint.After successfully calling this endpoint, you get a
202 response, meaning
the generation of the invoice has been scheduled. It usually only takes a few
seconds before you can retrieve the invoice using the GET /v1/orders/{id} /invoice endpoint.If you want a reliable notification when the invoice is ready, you can listen to the
order.updated webhook and check the is_invoice_generated field.⌘I
Go (SDK)
package main
import(
"context"
"os"
macropaygo "github.com/web3group/macropay-go-main"
"log"
)
func main() {
ctx := context.Background()
s := macropaygo.New(
macropaygo.WithSecurity(os.Getenv("MACROPAY_ACCESS_TOKEN")),
)
res, err := s.Orders.GenerateInvoice(ctx, "<value>")
if err != nil {
log.Fatal(err)
}
if res.Any != nil {
// handle response
}
}from macropay_sdk import Macropay
with Macropay(
access_token="<YOUR_BEARER_TOKEN_HERE>",
) as macropay:
res = macropay.orders.generate_invoice(id="<value>")
# Handle response
print(res)import { Macropay } from "@macropayments/sdk";
const macropay = new Macropay({
accessToken: process.env["MACROPAY_ACCESS_TOKEN"] ?? "",
});
async function run() {
const result = await macropay.orders.generateInvoice({
id: "<value>",
});
console.log(result);
}
run();declare(strict_types=1);
require 'vendor/autoload.php';
use Macropay;
$sdk = Macropay\Macropay::builder()
->setSecurity(
'<YOUR_BEARER_TOKEN_HERE>'
)
->build();
$response = $sdk->orders->generateInvoice(
id: '<value>'
);
if ($response->any !== null) {
// handle response
}curl --request POST \
--url https://api.macropay.ai/v1/orders/{id}/invoice \
--header 'Authorization: Bearer <token>'const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.macropay.ai/v1/orders/{id}/invoice', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://api.macropay.ai/v1/orders/{id}/invoice")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.macropay.ai/v1/orders/{id}/invoice")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"error": "MissingInvoiceBillingDetails",
"detail": "<string>"
}