PayPal: MerchantSDK DoExpressCheckoutPaymentResponse validation - php

What are the fields I should validate in DoExpressCheckoutPaymentResponse or is it necessary to validate it?
I was validating the :
$response->DoExpressCheckoutPaymentResponseDetails->PaymentInfo->SellerDetails->PayPalAccountID
But it does not seem to be always provided.
I also validate the GrossAmount (value and currencyCode) and TransactionID in a similar way.

The only thing you need to do is to check the ACK value of the DoExpressCheckout API call.
If the ACK=Success, the transaction completed successfully.
With the PHP merchant SDK you can do something like this:
$DoECReq = new DoExpressCheckoutPaymentReq();
$DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
try {
/* wrap API method calls on the service object with a try catch */
$DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq);
} catch (Exception $ex) {
include_once("../Error.php");
exit;
}
if(isset($DoECResponse)) {
echo "<table>";
echo "<tr><td>Ack :</td><td><div id='Ack'>$DoECResponse->Ack</div> </td></tr>";
if(isset($DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo)) {
echo "<tr><td>TransactionID :</td><td><div id='TransactionID'>". $DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->TransactionID."</div> </td></tr>";
}
echo "</table>";
echo "<pre>";
print_r($DoECResponse);
echo "</pre>";
}
It's advised by PayPal to integrate the IPN as well. I always rely on them before validating the payment.
There is more information about how to implement them on the PayPal developer website: https://developer.paypal.com/webapps/developer/docs/classic/products/instant-payment-notification/

Related

Security Error. Illegal access detected using ccavenue in php

I am successfully redirecting to ccavenue payment gateway but on clicking the cancel button it is showing the error "Security Error. Illegal access detected" in the redirect url page.
This is my redirecturl page:
<?php include('Aes.php');include('adler32.php')?>
<?php
$workingKey='myWorkingKey'; //Working Key should be provided here.
$encResponse=$_POST["encResponse"]; //This is the response sent by the CCAvenue Server
$rcvdString=decrypt($encResponse,$workingKey);
$AuthDesc="";
$MerchantId="";
$OrderId="";
$Amount=0;
$Checksum=0;
$veriChecksum=false;
$decryptValues=explode('&', $rcvdString);
$dataSize=sizeof($decryptValues);
echo "<center>";
for($i = 0; $i < $dataSize; $i++)
{
$information=explode('=',$decryptValues[$i]);
if($i==0) $MerchantId=$information[1];
if($i==1) $OrderId=$information[1];
if($i==2) $Amount=$information[1];
if($i==3) $AuthDesc=$information[1];
if($i==4) $Checksum=$information[1];
}
$rcvdString=$MerchantId.'|'.$OrderId.'|'.$Amount.'|'.$AuthDesc.'|'.$workingKey;
$veriChecksum=verifyChecksum(genchecksum($rcvdString), $Checksum);
if($veriChecksum==TRUE && $AuthDesc==="Y")
{
echo "<br>Thank you for shopping with us. Your credit card has been charged and your transaction is successful. We will be shipping your order to you soon.";
}
else if($veriChecksum==TRUE && $AuthDesc==="B")
{
echo "<br>Thank you for shopping with us.We will keep you posted regarding the status of your order through e-mail";
}
else if($veriChecksum==TRUE && $AuthDesc==="N")
{
echo "<br>Thank you for shopping with us.However,the transaction has been declined.";
}
else
{
echo "<br>Security Error. Illegal access detected";
}
echo "<br><br>";
echo "<table cellspacing=4 cellpadding=4>";
for($i = 0; $i < $dataSize; $i++)
{
$information=explode('=',$decryptValues[$i]);
echo '<tr><td>'.$information[0].'</td><td>'.$information[1].'</td></tr>';
}
echo "</table><br>";
echo "</center>";
?>
I googled about the issue but was not able to get any solution. How to solve this error..Please give some suggestions regarding the same?
I found from the documentation (might be outdated but i couldn't find an updated one) that you need to pass a paramater called cancel_url which CCAvenue will redirect the customer to this URL if the customer cancels the transaction on the billing page.
So in the page that you create the payment you need to add to your form something like this
<input type="hidden" id="cancel_url" name="cancel_url" value="the_url_where_you_will_proccess_canceled_orders">
You must already have something similar with redirect_url
There is nothing wrong with your code. You need to maintain separate page for cancel order, in which you need not to use CC avenue response code. Since, user didn't complete the payment you wont receive any response parameter from ccavenue. So, their is no need to $verifyCheckSum and $AuthDesc variables. They just cancelled their order willingly. So, just need to show them a msg "Your order has been cancelled", in your website.

PHP Gmail API - Send draft

How may I send a draft with GMAIL API and OAuth2.0 via PHP?
In the official docs there is no reference on how to achieve this with PHP.
Based on the Java example, I tried:
$drafts = array();
try {
$draftsResponse = $service->users_drafts->listUsersDrafts('me');
if ($draftsResponse->getDrafts()) {
$drafts = array_merge($drafts, $draftsResponse->getDrafts());
}
}
catch (Exception $e) {
echo 'An error occurred: ' . $e->getMessage();
}
var_dump($drafts);
foreach ($drafts as $draft) {
echo 'Draft with ID: ' . $draft->getId() . '<br/>';
$abc = $service->users_drafts->send('me',$draft->getId());
var_dump($abc);
}
But of course I am doing something wrong, because it is not working. The first var_dump() returns all drafts. But nothing else happens after that.
Can you please help me?
You have to create a new Google_Service_Gmail_Draft instance and use that, not just supply the id:
foreach ($drafts as $draft) {
$d = new Google_Service_Gmail_Draft();
$d->setId($draft->getId());
$service->users_drafts->send('me', $d);
}

PHP: json_decode stops further code from executing

this is my code:
echo "START";
echo "<br />";
try {
$check = json_decode($soundcloud->get('me/followings/2521254'), true);
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
exit($e->getMessage());
}
echo "<br />";
echo "END";
When I execute the file it looks like this:
START
The requested URL responded with HTTP code 303.
The HTTP code 303 does mean that the user is following a specific person (if not it's 404), but that's not the point - this question is not SoundCloud API related.
The actual problem is: the echo (echo "END";) after the try block isn't executing.
What's the problem, how can I solve this?

Working on Php solution for getting data from eCommerce Merchant to Validation page

I think this is a problem we Web Designers are going to run into frequently working with CMS scripts.
and with all the new shopping carts and eCommerce Payment Gateways coming out.
I have a Component with a newer shopping cart running on Joomla that generates a Unique
URL for each order. Need to process it in Authorize.net SIM
compatible Gateway. (Hosted Payment Page)
I used a 2 Form solution to get the correct information to the Gateway, and payment can be made successfully.
Now I have to get the data back to Validate the payment and update the shopping cart.
I need to move the response code data to a dynamic URL.
The Gateway only posts to a static URL.
They suggested I have the Gateway post back to a static page that then auto posts to the correct unique generated URL.
They advise that the static page will pick up the response elements the shopping cart requires in the database, and then push the information to the second URL that is unique to the Individual transaction.
Also advise redirect be Auto Post or Post.
The Developer kindly wrote a snippet of code that is supposed to pick up the unique identifier for the order, generate the correct URL and to act as the Redirect,
<?php
if($_POST || $_GET) {
$vik = explode('_', $_REQUEST['x_fp_sequence']);
$querystring = '';
foreach($_REQUEST as $k=>$v) {
$querystring .= '&'.$k.'='.$v;
}
header('Location: http://allstoplimo.com/reservations/index.php?option=com_vikrentcar&task=notifypayment&sid='.$vik[0].'&ts='.$vik[1].$querystring);
}
?>
Which I have tried to combine with static standard static receipt page example provided by the Gateway:
<?php
if ($_REQUEST['x_response_code'] == '1') {
echo "<p>";
echo "Your order was processed successfully. Here is your receipt.";
echo "Your order will be shipped in two business days.";
echo "</p>";
echo "<pre>";
echo $_REQUEST["exact_ctr"];
echo "</pre>";
if (!empty($_REQUEST["exact_issname"])) {
echo "<p>";
echo "Issuer: " .$_REQUEST["exact_issname"] . "<br/>";
echo "Confirmation Number: " . $_REQUEST["exact_issconf"];
echo "</p>";
}
echo "<p>";
$track_url = "http://allstoplimo.com/reservations/" . $_REQUEST["x_invoice_num"];
echo "You can track it at <a href=\"" . $track_url . "\">" .
$track_url . "</a>";
echo "</p>";
} elseif ($_REQUEST['x_response_code'] == '2') {
echo "<p>";
echo "Your payment failed.";
echo "Here is your receipt.";
echo "</p>";
echo "<pre>";
echo $_REQUEST["exact_ctr"];
echo "</pre>";
} else {
echo "<p>";
echo "An error occurred while processing your payment.";
echo "Please try again later.";
echo "</p>";
}
?>
The receipt info is posting to the static page but
Of course it is not redirecting anywhere???
Any suggestions on an alternative?

Problem using publishUserAction method to post to profile

I am using gigya php sdk, It works well I am able to post to user's wall or profile using socialise.setStatus method but I am have problems when I try to use the publishuseraction method. I get an error Invalid request signature.
$method = "socialize.publishUserAction";
$request = new GSRequest($apiKey,$secretKey,$method);
$userAction = new GSDictionary("{\"title\":\"This is my title\", \"userMessage\":\"This is a user message\", \"description\":\"This is a description\", \"linkBack\":\"http://google.com\", \"mediaItems\":[{\"src\":\"http://www.f2h.co.il/logo.jpg\", \"href\":\"http://www.f2h.co.il\",\"type\":\"image\"}]}");
$request->setParam("userAction", $userAction);
$request->setParam("uid", $userUID);
$response = $request->send();
if($response->getErrorCode()==0){
echo "Success";
} else {
echo ("Error: " . $response->getErrorMessage());
}
UPDATED AFTER USING $response->getLog()
apiMethod=socialize.publishUserAction
apiKey=correct_api_key
params={"userAction":{},uid":"MY_UID","format":"json","httpStatusCodes":"false"}
URL=http://socialize.gigya.com/socialize.publishUserAction postData=uid=urlencoded(MY_UID)&format=json&httpStatusCodes=false&apiKey=correct_api_keyƗtamp=1296229876&nonce=1.29622987636E%2B12&sig=HEdzy%2BzxetV8QvTDjdsdMWh0%2Fz8%3D
server= web504
I used both put method
$userAction = new GSDictionary();
$userAction->put("title", "This is my title");
$userAction->put("userMessage", "This is my user message");
$userAction->put("description", "This is my description");
$userAction->put("linkBack", "http://google.com");
$mediaItems = array();
$mediaItems[0] = new GSDictionary("{\"src\":\"http://www.f2h.co.il/logo.jpg\", \"href\":\"http://www.f2h.co.il\",\"type\":\"image\"}");
& JSON method
$userAction = new GSDictionary("{\"title\":\"This is my title\", \"userMessage\":\"This is a user message\", \"description\":\"This is a description\",
\"linkBack\":\"http://google.com\", \"mediaItems\":[ {\"src\":\"http://www.f2h.co.il/logo.jpg\", \"href\":\"http://www.f2h.co.il\",\"type\":\"image\"}]}");
I get the same error. And User action is empty using both methods. I appreciate any help.
Thanks.
Try calling getLog() for a bit more information about the error:
if($response->getErrorCode()==0){
echo "Success";
} else {
echo ("Error: " . $response->getErrorMessage());
print "<pre>";
print_r($response->getLog());
print "</pre>";
}
Also, are you able to run getUserInfo w/ the SDK? This is a simple test that also requires a signature. Use the example on the PHP SDK page (about 1/2 way down).

Categories