Jump to content

Payment error while creating order by webservice


arjit

Recommended Posts

Hi, 

 

I am trying to create order via prestashop webservices 

I have a valid customer. I am creating a cart, then making an order. I am pasting the body of request. I am getting error saying payment error in the back office Please let me know the mistake if anyone can help 

 

=========== cart =============

<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">

<cart>

 

<id_address_delivery>4</id_address_delivery>

<id_address_invoice>4</id_address_invoice>

<id_currency >1</id_currency>

<id_customer>1</id_customer>

 

<id_lang >1</id_lang>

<id_shop>1</id_shop>

<delivery_option/>

  <secure_key>90a3f0858c33fdecca22bfee2931a701</secure_key>

<allow_seperated_package>0</allow_seperated_package>

<date_add>2015-06-23 14:45:08</date_add>

<date_upd>2015-06-23 14:45:08</date_upd>

<associations><cart_rows>

<cart_row>

<id_product >1</id_product>

<id_product_attribute >0</id_product_attribute>

<id_address_delivery >0</id_address_delivery>

<quantity>3</quantity>

</cart_row>

</cart_rows>

</associations>

</cart>

</prestashop>

 

 

 

================ order ==================

<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">

<order>

  <id_address_delivery>4</id_address_delivery>

  <id_address_invoice>4</id_address_invoice>

  <id_cart>21</id_cart>

  <id_currency>1</id_currency>

  <id_lang>1</id_lang>

  <id_customer>1</id_customer>

  <id_carrier>3</id_carrier>

  <shipping_number notFilterable="true"/>

  <total_products_wt>53</total_products_wt>

  <conversion_rate>1.000000</conversion_rate>

  <module>cheque</module>

  <id_shop>1</id_shop>

  <payment>Payment by check</payment>

  <total_paid>3300</total_paid>

  <total_paid_tax_incl>3300</total_paid_tax_incl>

  <total_paid_tax_excl>3300</total_paid_tax_excl>

  <total_paid_real>3300</total_paid_real>

  <total_products>3</total_products>

  <total_shipping>2.000000</total_shipping>

<total_shipping_tax_incl>2.000000</total_shipping_tax_incl>

<total_shipping_tax_excl>2.000000</total_shipping_tax_excl>

<carrier_tax_rate>0.000</carrier_tax_rate>

<total_wrapping>0.000000</total_wrapping>

<total_wrapping_tax_incl>0.000000</total_wrapping_tax_incl>

<total_wrapping_tax_excl>0.000000</total_wrapping_tax_excl>

<round_mode>0</round_mode>

<conversion_rate>1.000000</conversion_rate>

<secure_key>90a3f0858c33fdecca22bfee2931a701</secure_key>

<associations>

<order_rows>

<order_row>

  <product_id>1</product_id>

  <product_quantity>3</product_quantity>

    <product_name>sofa</product_name>

    <product_price>1100</product_price>

</order_row>

</order_rows>

</associations>

</order>

</prestashop>

 

 

Please me know if I need to create any other resource.  

Link to comment
Share on other sites

  • 2 months later...

I have one question,

I succesfully create order via webservice, but not shown to back office, just in database, because delivery address and invoice address not inserted in database column, altough was POST: id_address_delivery and POST: id_address_invoice

 

After I input manually to the column, the order shown in backoffice.

 

Any ideas?

 

Thank you

Edited by An'im Fahmy (see edit history)
Link to comment
Share on other sites

  • 1 year later...

Hi,

 

I'm using the php code below to add a request via webservice:
 

 

<?php
    header('Content-type: text/html; charset=utf-8');
     
    define('DEBUG', true);
    define('PS_SHOP_PATH', 'http://www.site.com');
    define('PS_WS_AUTH_KEY', '*********');
    
    require_once('../PSWebServiceLibrary.php');
    $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
   
    $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/orders?schema=blank'));
    
    $xml->order->id_customer = '27';
    $xml->order->id_address_delivery = '57';
    $xml->order->id_address_invoice = '57';
    $xml->order->id_cart = '113';
    $xml->order->id_shop = '1';
    $xml->order->current_state = '2';

     $xml->order->id_shop_group = '1';
    $xml->order->id_currency = '1';
    $xml->order->id_lang = '1';
    $xml->order->id_carrier = '6';
    $xml->order->payment = 'cheque';
    $xml->order->module = 'cheque';
    $xml->order->total_paid = '400';
    $xml->order->total_paid_real = '400';
    $xml->order->total_products = '400';
    $xml->order->total_products_wt = '400';
    $xml->order->conversion_rate = '1';
    
    $xml->order->associations->order_rows->order_row->product_id = $product['id'];
    $xml->order->associations->order_rows->order_row->product_quantity = $_POST['quantity'];
    
    $opt = array('resource' => 'orders');
    $opt['postXml'] = $xml->asXML();
    $xml = $webService->add($opt);
    
    ?>
 


However, the payment validation error appears (it is occurring with all installed payment modules):

 

 

RETURN HTTP BODY
Fatal error: Uncaught exception 'PrestaShopException' with message 'Can't save Order Payment' in /home/quartinho/public_html/classes/PaymentModule.php:413Stack trace:#0 /home/quartinho/public_html/classes/order/Order.php(1572): PaymentModuleCore->validateOrder('113', '12', '400', 'cheque', NULL, Array, NULL, false, 'd6fc369babff846...')#1 /home/quartinho/public_html/classes/webservice/WebserviceRequest.php(1477): OrderCore->addWs()#2 /home/quartinho/public_html/classes/webservice/WebserviceRequest.php(1291): WebserviceRequestCore->saveEntityFromXml(201)#3 /home/quartinho/public_html/classes/webservice/WebserviceRequest.php(518): WebserviceRequestCore->executeEntityPost()#4 /home/quartinho/public_html/webservice/dispatcher.php(87): WebserviceRequestCore->fetch('TB7MVCRV1D7MH6X...', 'POST', 'orders', Array, false, '<?xml version="...')#5 {main}  thrown in /home/quartinho/public_html/classes/PaymentModule.php on line 413


Pretashop 1.6.1.4

Any suggestions?
Thank you

Link to comment
Share on other sites

not enough information for any of us to troubleshoot for you.  check your php error logs to see if there is any more helpful errors, otherwise you'll just need to dig into the code and see what exactly is causing it to fail.

 

Thanks for the reply, the only additional error you found was this:

 

 

Fatal error: Uncaught exception 'PrestaShopWebserviceException' with message 'HTTP XML response is not parsable: array ( 0 => LibXMLError::__set_state(array( 'level' => 3, 'code' => 4, 'column' => 1, 'message' => 'Start tag expected, \'<\' not found ', 'file' => '', 'line' => 2, )), )' in /home/quartinho/public_html/webservice-teste/PSWebServiceLibrary.php:207 Stack trace: #0 /home/quartinho/public_html/webservice-teste/PSWebServiceLibrary.php(242): PrestaShopWebservice->parseXML('?Fatal error: U...') #1 /home/quartinho/public_html/webservice-teste/examples/pedido.php(37): PrestaShopWebservice->add(Array) #2 {main} thrown in /home/quartinho/public_html/webservice-teste/PSWebServiceLibrary.php on line 207

Link to comment
Share on other sites

PrestaShopWebservice->parseXML('?Fatal error: U...')

 

What is that Fatal error? 

 

I would suggest updating PSWebServiceLibrary.php (parseXML function) and print out the $response variable to see what that fatal error is.  The library is expecting a valid XML response, but is instead receiving some kind of Fatal error which will likely contain a stack trace

Link to comment
Share on other sites

What is that Fatal error? 

 

I would suggest updating PSWebServiceLibrary.php (parseXML function) and print out the $response variable to see what that fatal error is.  The library is expecting a valid XML response, but is instead receiving some kind of Fatal error which will likely contain a stack trace

 

I print $response:

 

Fatal error: Uncaught exception 'PrestaShopException' with message 'Can't save Order Payment' in /home/quartinho/public_html/classes/PaymentModule.php:413 Stack trace: #0 /home/quartinho/public_html/classes/order/Order.php(1572): PaymentModuleCore->validateOrder('113', '12', '400', 'cheque', NULL, Array, NULL, false, 'd6fc369babff846...') #1 /home/quartinho/public_html/classes/webservice/WebserviceRequest.php(1477): OrderCore->addWs() #2 /home/quartinho/public_html/classes/webservice/WebserviceRequest.php(1291): WebserviceRequestCore->saveEntityFromXml(201) #3 /home/quartinho/public_html/classes/webservice/WebserviceRequest.php(518): WebserviceRequestCore->executeEntityPost() #4 /home/quartinho/public_html/webservice/dispatcher.php(87): WebserviceRequestCore->fetch('TB7MVCRV1D7MH6X...', 'POST', 'orders', Array, false, '

 

In this part of the code (PaymentModule.php:413 ) the problem is occurring, but I do not know how to solve it:

                 // Original code commented and changed to another if

                 // if (!$order->addOrderPayment($amount_paid, null, $transaction_id)) {

                 if (!isset($order) || !Validate::isLoadedObject($order) || !$order->addOrderPayment($amount_paid, null, $transaction_id)) {

                    PrestaShopLogger::addLog('PaymentModule::validateOrder - Cannot save Order Payment', 3, null, 'Cart', (int)$id_cart, true);

413              throw new PrestaShopException('Can\'t save Order Payment');

                }

Edited by l4p84 (see edit history)
Link to comment
Share on other sites

Seems to me that you need to determine what condition in your custom if statement is failing.

if (!isset($order) || !Validate::isLoadedObject($order) || !$order->addOrderPayment($amount_paid, null, $transaction_id)) {

is $order an valid Order object?

or if $order is a valid Order object, then why is addOrderPayment function failing?

 

You will need to add further debug statements to find out the answer.

  • Like 1
Link to comment
Share on other sites

Seems to me that you need to determine what condition in your custom if statement is failing.

if (!isset($order) || !Validate::isLoadedObject($order) || !$order->addOrderPayment($amount_paid, null, $transaction_id)) {

is $order an valid Order object?

or if $order is a valid Order object, then why is addOrderPayment function failing?

 

You will need to add further debug statements to find out the answer.

 

Thanks again for helping.

 

The $order variable, I checked and was NULL, and there was an if before the creation of the $order variable, I removed the if and it worked.

 

Thank you very much Bellini :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...