billogram_callback

The WooCommerce Billogram Integration billogram callback function.

Description

billogram_callback(); 

Usage

  1. if ( !function_exists( 'billogram_callback' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-billogram-integration/woocommerce-billogram2-extended.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = billogram_callback(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/woocommerce-billogram2-extended.php  
  1. function billogram_callback() { 
  2. global $wpdb; 
  3. include_once("class-billogram2-api.php"); 
  4. $apiInterface = new WCB_API(); 
  5. $entityBody = file_get_contents('php://input'); 
  6. $billogram = json_decode($entityBody); 
  7. $invoice = $apiInterface->get_invoice($billogram->billogram->id); 
  8. $ocr_number = $billogram->billogram->ocr_number; 
  9. $orderID = $invoice->info->order_no; 
  10. $result = $wpdb->get_results("SELECT order_id FROM wcb_orders WHERE ocr_number = ".$ocr_number); 
  11. if($billogram->event->type == 'BillogramSent') { 
  12. logthis('BillogramEvent: '.$billogram->event->type); 
  13. logthis($billogram->billogram->id); 
  14. $wpdb->query("UPDATE wcb_orders SET invoice_id = '".$billogram->billogram->id."', invoice_no = ".$billogram->event->data->invoice_no.", ocr_number=".$ocr_number." WHERE order_id = ".$orderID); 
  15. return header("HTTP/1.1 200 OK"); 
  16. die(); // this is required to return a proper result 
  17. if($billogram->event->type == 'Payment') { 
  18. if(update_post_meta($result[0]->order_id, 'process_billogram_payment_on_order', $billogram->billogram->id) == false) { 
  19. logthis('duplicate_billogram_callback'); 
  20. return header("HTTP/1.1 200 OK"); 
  21. die(); // this is required to return a proper result 
  22. logthis('BillogramEvent: '.$billogram->event->type); 
  23. logthis($billogram->billogram->id); 
  24. $order = new WC_Order($result[0]->order_id); 
  25. //$order->update_status('processing', 'Billogram Invoice payment accepted. OCR Reference: '.$ocr_number ); 
  26. $order_post = get_post( $result[0]->order_id ); 
  27. $post_date = $order_post->post_date; 
  28. $post_date_gmt = $order_post->post_date_gmt; 
  29.  
  30. //$order->payment_complete($ocr_number); 
  31. payment_complete($order, $ocr_number); 
  32.  
  33. $this_order = array( 
  34. 'ID' => $result[0]->order_id,  
  35. 'post_date' => $post_date,  
  36. 'post_date_gmt' => $post_date_gmt 
  37. ); 
  38. wp_update_post( $this_order ); 
  39.  
  40. if($order->get_status() != 'completed') { 
  41. $order->add_order_note( 'Billogram Invoice payment accepted. OCR Reference: '.$ocr_number ); 
  42. $order->update_status('completed'); 
  43. return header("HTTP/1.1 200 OK"); 
  44. die(); // this is required to return a proper result 
  45. if($billogram->event->type == 'Credit') { 
  46. logthis('BillogramEvent: '.$billogram->event->type); 
  47. logthis($billogram->billogram->id); 
  48. $order = new WC_Order($result[0]->order_id); 
  49. if($order->get_status() != 'refunded') { 
  50. $order->update_status('refunded'); 
  51. return header("HTTP/1.1 200 OK"); 
  52. die(); // this is required to return a proper result 
  53. if($billogram->event->type == 'Deleted') { 
  54. return header("HTTP/1.1 200 OK"); 
  55. die(); 
  56. logthis('BillogramEvent: '.$billogram->event->type); 
  57. logthis($billogram->billogram->id); 
  58. return header("HTTP/1.1 200 OK"); 
  59. die(); // this is required to return a proper result