Magento Payment Failure at function callDoDirectPayment() - php

I am having trouble debugging the payment gateway on Magento 1.6.1 using Paypal Payments Pro. It keeps failing with the message 'There was an error processing your order. Please contact us or try again later".
I have tried examining the error logs, and have posted the results below. First time using this system and more of a front end dev but I'm managing to kind of follow along with the php.
The key line where it appears to fail is
$this->_importFromResponse($this->_doDirectPaymentResponse, $response);
Could someone explain exactly what this line does? What a sensible next step in investigating this process should be? Any additional paypal / magento specific knowledge more than welcome!
I'm guessing that since the array is created then it could be a problem transferring to paypal (my api signature should be okay - the express gateway works)- how would I go about confirming or rebuking this hypothesis?
Thanks
(first 8 lines of the var/exception.log- with the referenced code snippets, and also some extra content from the var/system.log produced by the Mage::log() functions.)
exception 'Mage_Core_Exception' with message 'There was an error processing your order.
Please contact us or try again later.' in /var/www/magento/app/Mage.php:563
Stack trace:
#0 /var/www/magento/app/code/core/Mage/Paypal/Model/Api/Nvp.php(974):
Mage::throwException('There was an er...')
if (!$this->_validateResponse($methodName, $response)) {
Mage::logException(new Exception(
Mage::helper('paypal')->__("PayPal response hasn't required fields.")
));
Mage::throwException(Mage::helper('paypal')->__('There was an error processing
your order.
Please contact us or try again later.'));
}
#1 /var/www/magento/app/code/core/Mage/Paypal/Model/Api/Nvp.php(648):
Mage_Paypal_Model_Api_Nvp->call('DoDirectPayment', Array)
public function callDoDirectPayment()
{
Mage::log("hello world");
// 2013-03-20T00:04:50+00:00 DEBUG (7): hello world
$request = $this->_exportToRequest($this->_doDirectPaymentRequest);
Mage::log($request);
// 2013-03-20T00:04:50+00:00 DEBUG (7): Array
$this->_exportLineItems($request);
if ($this->getAddress()) {
$request = $this->_importAddresses($request);
}
$response = $this->call(self::DO_DIRECT_PAYMENT, $request);
Mage::log($response);
(
[PAYMENTACTION] => Authorization
[IPADDRESS] => 81.98.95.116
[RETURNFMFDETAILS] => 1
[AMT] => 0.50
[CURRENCYCODE] => GBP
[INVNUM] => 100000063
[NOTIFYURL] => http://www.store.com/paypal/ipn/
[EMAIL] => hello#email
[CREDITCAR] => xxxxxxxxxxxxxx
[EXPDATE] => xxxxxx
[CVV2] => XXX
[ISSUENUMBER] =>
)
$this->_importFromResponse($this->_doDirectPaymentResponse, $response);
Mage::log("nothing to see here")
// This returns nothing to the system.log and so I assume is the point of failure
}
#2 /var/www/magento/app/code/core/Mage/Paypal/Model/Direct.php(343):
Mage_Paypal_Model_Api_Nvp->callDoDirectPayment()
// call api and import transaction and other payment information
/**
* Place an order with authorization or capture action
*
* #param Mage_Sales_Model_Order_Payment $payment
* #param float $amount
* #return Mage_Paypal_Model_Direct
*/
protected function _placeOrder(Mage_Sales_Model_Order_Payment $payment, $amount)
{ //...........(343)
$api->callDoDirectPayment();
$this->_importResultToPayment($api, $payment);
try {
$api->callGetTransactionDetails();
} catch (Mage_Core_Exception $e) {
// if we recieve errors, but DoDirectPayment response is Success, then set
Pending status for transaction
$payment->setIsTransactionPending(true);
}
(343)
$this->_importResultToPayment($api, $payment);
return $this;
}
#3 /var/www/magento/app/code/core/Mage/Paypal/Model/Direct.php(178):
Mage_Paypal_Model_Direct->_placeOrder(Object(Mage_Sales_Model_Order_Payment), 45)
#4 /var/www/magento/app/code/core/Mage/Sales/Model/Order/Payment.php(1026):
Mage_Paypal_Model_Direct->authorize(Object(Mage_Sales_Model_Order_Payment), 45)
#5 /var/www/magento/app/code/core/Mage/Sales/Model/Order/Payment.php(311):
Mage_Sales_Model_Order_Payment->_authorize(true, 45)
#6 /var/www/magento/app/code/core/Mage/Sales/Model/Order.php(855):
Mage_Sales_Model_Order_Payment->place()
#7 /var/www/magento/app/code/core/Mage/Sales/Model/Order.php(1073):
Mage_Sales_Model_Order->_placePayment()
#8 [internal function]: Mage_Sales_Model_Order->place()

Do you have debugging enabled in your PayPal settings in Magento? If so, then you should see a log show up in /var/log so you can see the RAW request and response data that was sent back and forth.
This will allow you to see the actual error code and message that came back in the response which will help you figure out what exactly went wrong.

Related

Stripe Refund on connected account

i would like to refund a payment on a connected account. Therefore I'm using the following code:
$acc = \Stripe\Account::retrieve($conn_account);
$ch_id = "ch_XXXXXXXXXXXXX";
/*$ch = $stripe->charges->capture(
$ch_id,
[],
['stripe_account' => $conn_account ]
);
echo $ch;
*/
$stripe->refunds->create([
'charge' => $ch_id,
]);
Running the pgp returns
Fatal error: Uncaught (Status 404) (Request req_XXXXXXXX) No such charge: 'ch_XXXXXXXXXXXXXXXXXXX'
thrown in C:\xampp\htdocs\user\vendor\stripe\stripe-php\lib\Exception\ApiErrorException.php on line 38<br /
How can I solve this?
Thanks!
Did you created the charge by setting Stripe-Account header to your connected account ID? If so, you need to also set the Stripe-Account header when creating your refund. Your code should look like this:
$stripe->refunds->create(
['charge' => $ch_id ],
['stripe_account' => $conn_account ]
);
You can take a look at the documentation for more information (like refunding application fees): https://stripe.com/docs/connect/direct-charges#issuing-refunds

Stripe doubles anything

I am using a function I created that I have tried creating customers from, and creating charges from. For whatever reason it seems to be double charging in test mode (Not bringing into live mode under these conditions) and I'm trying to understand why. I had it going through a few functions so I made it all happen in one function to make sure that it had nothing to do with what I had made. I'm lost on why this is happening. I try to make charges from token, doubles in less than a second. I try to create a customer from token, doubles in less than a second. I am using Stripes latest stripe-php library.
public function invoice($invoice = null) {
//Provides billing info for invoice.ctp
$this->loadModel('Invoice');
$billingi = $this->Invoice->get($invoice, [
'contain' => ['Items'],
]);
$dollars = 0;
foreach ($billingi->items as $item) {
$dollars += $item->price;
}
$cents = bcmul($dollars, 100);
$price = floatval($cents);
if ($this->request->is('post')) {
$stripeToken = $this->request->data('stripeToken');
//Sets stripe API
\Stripe\Stripe::setApiKey("sk_test_QVYouMViTf1k3zfVu2VAyZge");
//Retrieves stripe token from stripe API
//$response = \Stripe\Token::retrieve($stripeToken);
\Stripe\Customer::create(array(
"description" => "Test customer",
"source" => $stripeToken // obtained with Stripe.js
));
$this->Flash->success(__('Thank you for your payment!'));
return $this->redirect(['action' => 'approved', $invoice]);
}
/*
if ($response && $this->checkExists($response->card->cvc_check, $response->card->address_zip_check) == true) {
$this->insertCharge($invoice, $response, $price);
} else {
//Throw error because cvc_check or zip came back null (doesn't exist)
}
}
*/
$this->set('billingi', $billingi);
$this->set('_serialize', ['billing']);
}
The reason why there are things commented out is because I wanted to test the function without it, but adding it back later when I understand what the issue is.
In your code, the only API request sent to Stripe is a customer creation request (\Stripe\Customer::create(...)).
This doesn't charge the user -- it merely validates the card from the token in the source parameter, and creates a persistent customer object that you can in turn use to create actual charges. This tutorial explains this flow.
There's nothing in your code that would cause the API request to be sent twice. It's very unlikely the issue is on Stripe's end. More likely, your code is being called twice for some reason that's not related to Stripe. You'd need to add traces to your code to figure out what exactly is being called in what order.

Trouble understanding Facebook Uncaught Exception

I'm super new to Facebook PHP SDK. I am having trouble understanding the stack trace below; where should I look for the error?
The Facebook Scheduled posts are successfully processing, however, this error causes a bad user experience, but, everything else in my program is working fine. It looks like it may be trying to process something that isn't there.
The last line of code being executed (I know because the scheduled posts show up in my Facebook Test Account) is:
$responses = $fb->sendBatchRequest(($batch), $this->session->userdata('fb_access_token'));
$batch is defined as:
foreach($esdarr as $key => $event_start_datetime){$sched_time = strtotime($event_start_datetime)- 18000;
$event_end_datetime = $eedarr[$key];
$requestScheduleEvent = $fb->post('/'.$band_page_id.'/feed', ['message' => $band_name.' is playing today at '.$venue_name.' '.date('(l), g:ia', strtotime($event_start_datetime)), 'published'=>false, 'scheduled_publish_time'=>$sched_time], $pageToken);
$batch[$key]=$requestScheduleEvent;
}
This is all within a CI Controller (event.php) with public function add(). Then I get this error:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Argument for add() must be of type array or FacebookRequest.' in /home/my_user/public_html/development/application/vendor/facebook/php-sdk-v4/src/Facebook/FacebookBatchRequest.php:85 Stack trace:
#0 /home/my_user/public_html/development/application/vendor/facebook/php-sdk-v4/src/Facebook/FacebookBatchRequest.php(78): Facebook\FacebookBatchRequest->add(Object(Facebook\FacebookResponse), 0)
#1 /home/my_user/public_html/development/application/vendor/facebook/php-sdk-v4/src/Facebook/FacebookBatchRequest.php(61): Facebook\FacebookBatchRequest->add(Array)
#2 /home/my_user/public_html/development/application/vendor/facebook/php-sdk-v4/src/Facebook/Facebook.php(492): Facebook\FacebookBatchRequest->__construct(Object(Facebook\FacebookApp), Array, 'EAAYzEGW0ZAsoBA...', 'v2.7')
#3 /home/my_user/public_html/development/application/controllers/user/event.php(777): Facebook\Facebook->sendBatchRequest(Array, 'EAAYzEGW0ZAsoBA...')
#4 [internal function]: Event->add in /home/my_user/public_html/development/application/vendor/facebook/php-sdk-v4/src/Facebook/FacebookBatchRequest.php on line 85
If I change line #85 of FacebookBatchRequest.php as follows (that is; redirect the page to the correct URL within the CI structure), everything seems to work fine:
public function add($request, $name = null)
{
if (is_array($request)) {
foreach ($request as $key => $req) {
$this->add($req, $key);
}
return $this;
}
if (!$request instanceof FacebookRequest) {
***redirect('user/event');***
throw new \InvalidArgumentException('Argument for add() must be of type array or FacebookRequest.');
}
$this->addFallbackDefaults($request);
$requestToAdd = [
'name' => $name,
'request' => $request,
];
Of course, this is a tenuous workaround at best. So, I'd like to know why the error is being thrown in the first place.
If you defined add() in your program and add() is also built in to the SDK, it won't work. Try using a different name.
If that isn't the problem, can you please post your code? Perhaps one of us can find it.
What language are you using? Perhaps you just have a syntax error.
I hope this helps in any way!
Okay, this ended up being an erroneous use of the batch process on my part.
$requestScheduleEvent = $fb->post('/'.$band_page_id.'/feed', ['message' => $band_name.' is playing today at '.$venue_name.' '.date('(l), g:ia', strtotime($event_start_datetime)), 'published'=>false, 'scheduled_publish_time'=>$sched_time], $pageToken);
Needed to use the request method:
$batch[$key] = $fb->request('POST', '/'.$band_page_id.'/feed', ['message' => $band_name.' is playing today at '.$venue_name.' '.date('(l), g:ia', strtotime($event_start_datetime)), 'published'=>false, 'scheduled_publish_time'=>$sched_time], $pageToken);

Google+ API CommentActivity return 400 Error

I'm having no luck calling the Google+ API for pushing a CommentActivity moment.
I have been able to push an AddActivity successfully as well as a DiscoverActivity.
I read somewhere on the internet whilst searching for a solution that the 400 HTTP Status represents that my user credentials are invalid, but I have been able to post AddActivity & DiscoverActivity after trying CommentActivity and I have tried disconnecting and reconnecting my account and linking the required credentials to no avail.
Here's my code to generate the moment, I believe this is the error, and it's probably something to do with the use of a Target and a Result in this moment type (Neither DiscoverActivity nor AddActivity have a Result field). In particular, the Target's and Result's URLs are the same but the Result's has an appended anchor. The documentation implies that this should work fine, however.
$moment = new Google_Moment();
$moment->setType("http://schemas.google.com/CommentActivity");
$target = new Google_ItemScope();
$target->setUrl(get_permalink($comment->comment_post_id));
$target->setType("http://schema.org/Article");
$moment->setTarget($target);
$result = new Google_ItemScope();
$result->setId("comment-".$comment_id);
$result->setType("http://schema.org/Comment");
$result->setUrl(get_comment_link($comment_id));
$result->setText($comment->comment_content);
$moment->setResult($result);
Soci_Base::getSocial("google")->getUser($user)->GPlus->moments->insert('me', 'vault', $moment);
GPlus is a reference to a Google_PlusService object.
Here's my exception I receive with stack trace (Pointless parts of the files are omitted, hooks.php and plugin.php are not the Google+ API)
Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling POST https://www.googleapis.com/plus/v1/people/me/moments/vault?key=AIzaSyBa27u5PtBgFHO4SY_Fq9_0sO39pFWrRzE: (400) Invalid Value' in /~/src/io/Google_REST.php:66 Stack trace:
#0 /~/G+/src/io/Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest))
#1 /~/G+/src/service/Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest))
#2 /~/G+/src/contrib/Google_PlusService.php(167): Google_ServiceResource->__call('insert', Array)
#3 /~/hooks.php(54): Google_MomentsServiceResource->insert('me', 'vault', Object(Google_Moment))
#4 /~/plugin.php(406): soci_comment('108040')
#5 /~ in /~/lib/G+/src/io/Google_REST.php on line 66
I think that's all of the info I have on the matter - I have no idea to get the exact HTTP request the script makes.
Thank you in advance for any and all help and for even having a look ^_^
Here's the code for the whole login sequence:
Soci_Google::addActionRequirement('http://schemas.google.com/AddActivity');
Soci_Google::addActionRequirement('http://schemas.google.com/CommentActivity');
Soci_Google::addActionRequirement('http://schemas.google.com/CreateActivity');
Soci_Google::addActionRequirement('http://schemas.google.com/DiscoverActivity');
Soci_Google::addActionRequirement:
public static function addActionRequirement($url) {
self::$activities[] = $url;
}
self::$token is just a reference to a string
$ret = new Soci_Google();
self::$users[$id] = $ret;
$ret->setToken(self::$meta->getMeta($user, self::$token));
return $ret;
Soci_Google __construct():
public function __construct() {
$this->googleObj = new Google_Client();
$this->googleObj->setApplicationName(self::$appName);
$this->googleObj->setClientId(self::$clientID);
$this->googleObj->setClientSecret(self::$clientSecret);
$this->googleObj->setRedirectUri(self::$redirectURI);
$this->googleObj->setDeveloperKey(self::$devKey);
$this->GPlus = new Google_PlusService($this->googleObj);
$this->googleObj->setRequestVisibleActions(self::$activities);
}
Soci_Goolge setToken
$this->googleObj->setAccessToken($googleUsrToken);

shopify Unprocessable Entity

while running this code with the app instalation,i am getting the Unprocessable Entity status code 422 error.
Here is the code
$sc = new ShopifyClient($_SESSION['shop'], $_SESSION['token'], $api_key, $secret);
$charge = array
(
"webhooks"=> array
(
"topic"=>"orders/create",
"address"=>"http://www.abc123no.com/nomi/s.php?key=123456789",
"format"=>"json"
)
);
try
{
$webhooks = $sc->call('POST','/admin/webhooks.json',$charge);
}
catch (ShopifyApiException $e)
{
var_dump($e->getResponseHeaders());
}
Error code 422 is for validation errors. The body of the response will describe the error to help you debug your application.
e.g. The response might be: {"errors":{"address":["for this topic has already been taken"]}}
Your error appears to be from using the wrong format for the request. The create endpoint doesn't take an array of webhooks, and you should use the singular "webhook" for the top-level key.
The Webhook API documentation has the correct format for the request body.
Change webhooks to webhook , it might create bad request error
"**webhooks**"=> array
(
"topic"=>"orders/create",
"address"=>"http://www.abc123no.com/nomi/s.php?key=123456789",
"format"=>"json"
)

Categories