Skip to content

Commit 4847e44

Browse files
committed
Customize invoice description (embedded in QR)
1 parent bd47fc9 commit 4847e44

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

woocommerce-gateway-lightning.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ public function process_payment( $order_id ) {
9999

100100
if (!$invoice) {
101101
$invoice = $this->strike->invoice([
102-
'currency' => $order->get_currency(),
103-
'amount' => $order->get_total(),
104-
'metadata' => [ 'order_id' => $order->get_id() ],
105-
'webhook' => self::get_webhook_url($order->get_id())
102+
'currency' => $order->get_currency(),
103+
'amount' => $order->get_total(),
104+
'description' => self::make_desc($order),
105+
'metadata' => [ 'order_id' => $order->get_id() ],
106+
'webhook' => self::get_webhook_url($order->get_id())
106107
]);
107108
$this->update_invoice($order, $invoice);
108109

@@ -209,6 +210,19 @@ protected static function get_qr_uri($invoice) {
209210
$image = $writer->writeString(strtoupper('lightning:' . $invoice->payreq));
210211
return 'data:image/png;base64,' . base64_encode($image);
211212
}
213+
214+
protected static function make_desc($order) {
215+
$total = $order->get_total() . ' ' .$order->get_currency();
216+
$desc = get_bloginfo('name') . ': ' . $total . ' for ';
217+
$products = $order->get_items();
218+
while (strlen($desc) < 100 && count($products)) {
219+
$product = array_shift($products);
220+
if (count($products)) $desc .= $product['name'] . ' x ' . $product['qty'] . ', ';
221+
else $desc = substr($desc, 0, -2) . ' and ' . $product['name'].' x '.$product['qty'];
222+
}
223+
if (count($products)) $desc = substr($desc, 0, -2) . ' and ' . count($products) . ' more';
224+
return $desc;
225+
}
212226
}
213227

214228
new WC_Gateway_Lightning();

0 commit comments

Comments
 (0)