Update to store payment id as a cookie
This will generate a cookie containing the buyer's payment id that will expire after 45 minutes to avoid generating a new payment id/integrated address each time that the page is reloaded.
This commit is contained in:
		
							parent
							
								
									feb9b1d24f
								
							
						
					
					
						commit
						bdf522e54a
					
				@ -200,6 +200,18 @@ class Monero_Gateway extends WC_Payment_Gateway
 | 
				
			|||||||
								return false;
 | 
													return false;
 | 
				
			||||||
				} 
 | 
									} 
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
 | 
									private function set_paymentid_cookie()
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										if(!isset($_COOKIE['payment_id']))
 | 
				
			||||||
 | 
										{ 
 | 
				
			||||||
 | 
											$payment_id  = bin2hex(openssl_random_pseudo_bytes(8));
 | 
				
			||||||
 | 
											setcookie('payment_id', $payment_id, time()+2700);
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										else
 | 
				
			||||||
 | 
											$payment_id = $_COOKIE['payment_id'];
 | 
				
			||||||
 | 
										return $payment_id;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
				public function instruction($order_id)
 | 
									public function instruction($order_id)
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
								$order       = wc_get_order($order_id);
 | 
													$order       = wc_get_order($order_id);
 | 
				
			||||||
@ -207,7 +219,7 @@ class Monero_Gateway extends WC_Payment_Gateway
 | 
				
			|||||||
								$currency    = $order->currency;
 | 
													$currency    = $order->currency;
 | 
				
			||||||
								$amount_xmr2 = $this->changeto($amount, $currency);
 | 
													$amount_xmr2 = $this->changeto($amount, $currency);
 | 
				
			||||||
								$address     = $this->address;
 | 
													$address     = $this->address;
 | 
				
			||||||
								$payment_id  = bin2hex(openssl_random_pseudo_bytes(8));
 | 
													$payment_id  = $this->set_paymentid_cookie();
 | 
				
			||||||
								$uri         = "monero:$address?amount=$amount?payment_id=$payment_id";
 | 
													$uri         = "monero:$address?amount=$amount?payment_id=$payment_id";
 | 
				
			||||||
								$array_integrated_address = $this->monero_daemon->make_integrated_address($payment_id);
 | 
													$array_integrated_address = $this->monero_daemon->make_integrated_address($payment_id);
 | 
				
			||||||
								if(isset($array_integrated_address)){
 | 
													if(isset($array_integrated_address)){
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user