Jump to content

Help In Custom Paypal Express Checkout Gateway


activa

Recommended Posts

Hello

 

we are working in the paypal express checkout gateway , wehave almost done all the code, but when we test it we have some probleme in the callback .

 

we pass the payment to paypal site and it show a successfull payment , and the gateway return the user to the blesta site to return url .

 

in the log no entries for successfull or failed reponse , also no transaction are stored in the clients side .

 

 

the validate function is the fallowing , is there any mistake in it ?

	public function validate(array $get, array $post) {

		print_r($get);
		$client_id = $this->ifSet($get['client_id']);
		$token = $this->ifSet($get['token']);
		// $payer_id = $this->ifSet($get['PayerID']);
		
		// if (!$client_id) {
			// $client_id = $this->clientIdFromEmail($this->ifSet($post['payer_email']));
		// }
		
		$post_to = $this->getApiUrl();
		
		$params = array(
			'TOKEN' => $token,
		);
		
		$response = $this->execute_request("GetExpressCheckoutDetails", $params);
		
		// Exit when we don't get a sucess request
		if (isset($response['ACK']) && $response['ACK'] != 'Success') {
			$this->Input->setErrors($this->getCommonError("invalid"));			
			// Log error response
			$this->log($this->ifSet($post_to), serialize($response), "input", false);
			return;
		}

		// Log Success response
		$this->log($this->ifSet($post_to), serialize($response), "input", true);
			
		// Do the payment
		$request_params = array(
			'TOKEN' => $response['TOKEN'],
			'PAYERID' => $response['PAYERID'],
			'PAYMENTREQUEST_0_AMT' => $response['PAYMENTREQUEST_0_AMT'],
			'PAYMENTREQUEST_0_PAYMENTACTION' => $this->payment_action,
			'PAYMENTREQUEST_0_CURRENCYCODE' => $this->currency,
		);

		// Make the call to PayPal to finalize payment
		$do_response =  $this->execute_request("DoExpressCheckoutPayment", $request_params);

	
		// Exit when we don't get a sucess request
		if (isset($do_response['ACK']) && $do_response['ACK'] != 'Success') {
			$this->Input->setErrors($this->getCommonError("invalid"));			
			// Log error response
			$this->log($this->ifSet($post_to), serialize($do_response), "input", false);
			return;
		}
			
		$this->log($this->ifSet($post_to), serialize($do_response), "output", true);
		
		// Capture the IPN status, or reject it if invalid
		switch (strtolower($this->ifSet($do_response['PAYMENTINFO_0_PAYMENTSTATUS']))) {
			case "completed":
			case "processed":
			case "completed-funds-held":
				$status = "approved";
				break;
			case "pending":
			case "in-progress":
				$status = "pending";
				break;
			case "refunded":
				$status = "refunded";
				break;
			case "voided":
				$status = "voided";
				break;
			case 'denied':
			case 'failed':			
			case 'expired':			
				$status = 'declined';
				break;				
			default:
				// Log request received, even though not processed
				$this->log($this->ifSet($post_to), serialize($do_response['PAYMENTINFO_0_PAYMENTSTATUS']), "output", true);
				return;
		}
		
		return array(
			'client_id' => $client_id,
			'amount' => $this->ifSet($do_response['PAYMENTREQUEST_0_AMT']),
			'currency' => $this->ifSet($do_response['PAYMENTREQUEST_0_CURRENCYCODE']),
			'status' => $status,
			'reference_id' => null,
			'transaction_id' => $this->ifSet($do_response['PAYMENTINFO_0_TRANSACTIONID']),
			// 'parent_transaction_id' => $this->ifSet($post['parent_txn_id']),
			// 'invoices' => $this->unserializeInvoices($this->ifSet($post['custom']))
		);
	}
	
Link to comment
Share on other sites

$this->log($this->ifSet($post_to), serialize($response), "input", false);

 

I don't know if that's the problem here, but if you use Blesta's log function with the first (url) parameter empty -which could happen here if $post_to is empty-, nothing gets logged and it terminates the script with a fatal Error: a:1:{s:3:"url";a:1:{s:5:"empty";s:12:"Missing URL.";}} exception.

 

We have had an issue with that as well.

In our module log() was being called with empty first parameter only when run under crontab. One of those places where nobody sees error messages being printed, and nothing got logged.

Link to comment
Share on other sites

Post_to is not empty it get the live or sandbox URL .

 

Ok.

Thought that may not be always the case, because of the ifSet()

 

==

 

 

is like a callback not recieved ...

 

 

You did include your class name in the callback URL, so that the request gets routed to your class?

 

As in:

 

$callbackurl = Configure::get("Blesta.gw_callback_url").Configure::get("Blesta.company_id")."/".strtolower(get_class($this))."/";

 

 

In case you are not able to find your problem, you may also able to use Paypal Express through our Omnipay module.

Link to comment
Share on other sites

Ok.

Thought that may not be always the case, because of the ifSet()

 

==

 

 

 

 

You did include your class name in the callback URL, so that the request gets routed to your class?

 

As in:

 

$callbackurl = Configure::get("Blesta.gw_callback_url").Configure::get("Blesta.company_id")."/".strtolower(get_class($this))."/";

 

 

In case you are not able to find your problem, you may also able to use Paypal Express through our Omnipay module.

 

 i will check it just for inspiration , because we need a separate gateway for checkout . and we will adding the incontext feature checkout later .

Link to comment
Share on other sites

Hello

$notify_url = Configure::get("Blesta.gw_callback_url") . Configure::get("Blesta.company_id") ."/paypal_express_checkout/?client_id=" . $this->ifSet($contact_info['client_id']) ;

in the developper section a see a successfull transaction .

 

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...