mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 11:17:34 -04:00 
			
		
		
		
	Improve logic in processWebhookRequest to handle more cases
This commit is contained in:
		
							parent
							
								
									749b58500e
								
							
						
					
					
						commit
						3cfffa09c4
					
				| @ -111,37 +111,46 @@ class BlockonomicsPaymentDriver extends BaseDriver | |||||||
|     public function processWebhookRequest() |     public function processWebhookRequest() | ||||||
|     { |     { | ||||||
| 
 | 
 | ||||||
|         // TODO: Include logic to create new payment with pending status in case user sends payment to the address after navigating away from the payment page
 |         $url_callback_secret = $_GET['secret']; | ||||||
|  |         $db_callback_secret = $this->getCallbackSecret(); | ||||||
|  | 
 | ||||||
|  |         if ($url_callback_secret != $db_callback_secret) { | ||||||
|  |             throw new PaymentFailed('Secret does not match'); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         $txid = $_GET['txid']; |         $txid = $_GET['txid']; | ||||||
|         $value = $_GET['value']; |         $value = $_GET['value']; | ||||||
|         $status = $_GET['status']; |         $status = $_GET['status']; | ||||||
|         $addr = $_GET['addr']; |         $addr = $_GET['addr']; | ||||||
|                  |                  | ||||||
|         $payment = $this->getPaymentByTxid($txid); |         $payment = $this->getPaymentByTxid($txid); | ||||||
|         $callbackSecret = $this->getCallbackSecret(); |  | ||||||
|          |          | ||||||
|         //Match secret for security
 |         if (!$payment) { | ||||||
|         if ($_GET['secret'] != $callbackSecret) { |             // TODO: Implement logic to create new payment in case user sends payment to the address after closing the payment page
 | ||||||
|             throw new PaymentFailed('Secret does not match'); |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         // Only accept confirmed transactions
 |  | ||||||
|         if ($status != 2) { |  | ||||||
|             throw new PaymentFailed('Transaction not confirmed'); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         switch ($status) { | ||||||
|  |             case 0: | ||||||
|  |                 $statusId = Payment::STATUS_PENDING; | ||||||
|  |                 break; | ||||||
|  |             case 1: | ||||||
|  |                 $statusId = Payment::STATUS_PENDING; | ||||||
|  |                 break; | ||||||
|  |             case 2: | ||||||
|                 $statusId = Payment::STATUS_COMPLETED; |                 $statusId = Payment::STATUS_COMPLETED; | ||||||
|  |                 break; | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         // Save the updated payment status
 |         if($payment->status_id == $statusId) { | ||||||
|         if ($payment->status_id != $statusId) { |             header('HTTP/1.1 200 OK'); | ||||||
|  |             echo "No change in payment status"; | ||||||
|  |         } else { | ||||||
|             $payment->status_id = $statusId; |             $payment->status_id = $statusId; | ||||||
|             $payment->save(); |             $payment->save(); | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|             header('HTTP/1.1 200 OK'); |             header('HTTP/1.1 200 OK'); | ||||||
|         echo "Success"; |             echo "Payment status updated successfully"; | ||||||
|         return; |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user