Hello,
I am using wpinv_insert_invoice() function to create invoice programmatically. It worked very well locally, however, when I hosted it on my web host my IP is getting blocked by https://bitninja.io/. This is a server security platform being used by web host.
Interestingly, when I create invoice from wordpress admin, it works just fine. However, when I try same thing programmatically my ip is getting blocked as this activity is being treated as some fraudulent activity by this security platform.
Please help me here. This is very critical. Following is the function which creates an invoice when a booking completes.
function create_invoice_when_booking_completes($post_id, $post, $update){
// Entertain if this is an update action on booking.
if($update && $post->post_type == 'booking'){
$bookingCharges = getAllBookingCharges($post_id);
$bookingInvoiceId = get_field( "booking_invoice_id", $post_id);
$bookingReference = get_field( "booking_reference", $post_id);
$bookingGuid = get_field( "booking_guid", $post_id);
$bookingDetailsUrl = getBookingDetailsUrl($bookingGuid);
$bookingState = get_field( "booking_state", $post_id);
$userNotes = array();
//Create invoice if it is not created already and booking state is created.
if(empty($bookingInvoiceId) && $bookingState == 'completed'){
$cartDetails = array();
if($bookingCharges){
array_push($userNotes, "Booking Details: " . "" . $bookingReference . "");
array_push($userNotes, "Booking Reference: " . $bookingReference);
foreach($bookingCharges as $charge){
if($charge['itemQuantity'] > 0){
array_push($cartDetails, array(
'id' => $charge['invoiceItemId'],
'quantity' => $charge['itemQuantity'],
'custom_price' => $charge['unitPrice']
));
}
}
}
$data = array(
'status' => 'wpi-pending',
'user_id' => get_post_field( 'post_author', $post_id ),
'cart_details' => $cartDetails,
'currency' => 'AUD',
'user_note' => implode("<br>", $userNotes)
);
if (function_exists('wpinv_insert_invoice')) {
$invoice = wpinv_insert_invoice( $data, true );
if ( is_wp_error( $invoice ) ) {
log_server_side_error('Invoice', 'Failed to CREATE Invoice', $invoice->get_error_message());
}
else{
update_field('booking_invoice_id', $invoice->ID, $post_id);
}
}
else{
log_server_side_error('Invoice', 'Failed to CREATE Invoice as wpinv_insert_invoice function from the plugin is not available.', "");
}
}
}
return;
}
Warm regards,
Arshad.