Automattic\WooCommerce\Gateways\PayPal

Request::generate_paypal_invoice_id_with_unique_suffixprivateWC 1.0

Generate a unique invoice ID for the order.

Method of the class: Request{}

No Hooks.

Returns

String.

Usage

// private - for code of main (parent) class only
$result = $this->generate_paypal_invoice_id_with_unique_suffix( $order ): string;
$order(WC_Order) (required)
Order object.

Request::generate_paypal_invoice_id_with_unique_suffix() code WC 10.7.0

private function generate_paypal_invoice_id_with_unique_suffix( WC_Order $order ): string {
	$prefix          = $this->gateway->get_option( 'invoice_prefix' );
	$order_number    = $order->get_order_number();
	$base_invoice_id = $prefix . $order_number;

	// Generate a unique ID for the invoice.
	$unique_id = bin2hex( random_bytes( 6 ) );

	$invoice_id = $this->limit_length( $base_invoice_id . '-' . $unique_id, PayPalConstants::PAYPAL_INVOICE_ID_MAX_LENGTH );
	return $invoice_id;
}