Trying to put an order via webservice. I've followed the correct order via webservice:
Create customer (customers blank schema)
Create customer's address (addresses blank schema)
Create associated customer's cart(carts blank schema)
Create Order (orders blank schema)
The problem is when order will be created and saved in database. I've launched the function which imports data into client + address + cart + order; aparently everything works fine, client, address and cart was created correctly, but not the order...
I've tested on php 5.6.30 server on my localhost lap and everything works fine but in a production php 5.5.9 server orders won't be created...
This is the function to create order:
$xml = $webService->get(array('url' => PS_SHOP_PATH .'api/orders/?schema=blank'));
$pedido = $xml->children()->children();
$direccion = getDireccion($idCliente, $webService);
$carrito = getCarrito($idCarrito, $webService);
$numProdPedido = count($carrito->associations->cart_rows->cart_row);
$pedido->id_address_delivery = $direccion['address']['id']; // Customer address
$pedido->id_address_invoice = $direccion['address']['id'];
$pedido->id_cart = $idCarrito;
$pedido->id_currency = $carrito->id_currency;
$pedido->id_lang = $carrito->id_lang;
$pedido->mp_order_id = $refPedido;
$pedido->reference = $refPedido;
$pedido->id_customer = $carrito->id_customer;
$pedido->id_carrier = $carrito->id_carrier;
$pedido->payment = $refPedido;//$pedido_ws['paymentType'];
$pedido->module = 'cashondelivery';
$pedido->total_paid = $pedido_ws['total_price'];
$pedido->total_paid_real = $pedido_ws['total_price'];
$pedido->total_products = $numProdPedido;
$pedido->total_products_wt = $numProdPedido;
$pedido->conversion_rate = 1;
// Others
$pedido->valid = '1';
$pedido->current_state = '1';
getEstadoPedido($pedido->order_state);
$pedido->total_discounts = $pedido_ws['promotions']['total_deduced_amount'];
$pedido->total_discounts_tax_incl = $pedido_ws['promotions']['total_deduced_amount'];
$pedido->total_discounts_tax_excl = $pedido_ws['promotions']['total_deduced_amount'];
$pedido->total_paid_tax_incl = $pedido_ws['total_price'];
$pedido->total_paid_tax_excl = $pedido_ws['total_price'];
$pedido->total_shipping = $pedido_ws['shipping_price'];
$pedido->total_shipping_tax_incl = $pedido_ws['shipping_price'];
$pedido->total_shipping_tax_excl = $pedido_ws['shipping_price'];
$ind = 0;
foreach($carrito->associations->cart_rows->cart_row as $producto){
$prod = getProductoById($producto->id_product, $webService);
$pedido->associations->order_rows->order_row[$ind]->product_id = $producto->id_product;
$pedido->associations->order_rows->order_row[$ind]->product_attribute_id = $producto->id_product_attribute;
$pedido->associations->order_rows->order_row[$ind]->product_quantity = $producto->quantity;
$pedido->associations->order_rows->order_row[$ind]->product_name = $prod->name->language[0];
$pedido->associations->order_rows->order_row[$ind]->product_reference = $prod->reference;
$pedido->associations->order_rows->order_row[$ind]->product_price = $prod->price;
$pedido->associations->order_rows->order_row[$ind]->unit_price_tax_incl = $prod->price;
$pedido->associations->order_rows->order_row[$ind]->unit_price_tax_excl = $prod->price;
$ind++;
}
// Creating the order
$opt = ['resource' => 'orders'];
$opt['postXml'] = $xml->asXML();
$xml = $webService->add($opt);
Any clues?
Edit: XML request and response code when calling order webservice. This is the last order xml.
HTTP REQUEST HEADER
POST //api/orders HTTP/1.1
Authorization: Basic WDMxSlRJRjFTNTNIMVlTS0hZRUFHTjlJVk5CQ1ZHTlg6
Host: www.mywebsite.com
Accept: */*
Content-Length: 1956
Content-Type: application/x-www-form-urlencoded
HTTP RESPONSE HEADER
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 26 Apr 2017 10:08:06 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Authorization,Accept-Encoding
X-Powered-By: PHP/5.5.9-1ubuntu4.19
Set-Cookie: PrestaShop-300d307acc0ec8525a71119b0dd393d8=0XUqFuC%2BvHy%2B%2BAU8Uod5odM7En0QQlQNh2ZWuI7VO6wTSlgh%2F%2FlVEDyz4e%2BJUv55b3N6fHTdEz%2Fmyjob65wxqjofdRVglsNIauli6yfcEBQ%3D000079; expires=Tue, 16-May-2017 10:08:05 GMT; Max-Age=1727999; path=/; domain=www.mywebsite.com; httponly
XML SENT
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<order>
<id/>
<id_address_delivery>31754</id_address_delivery>
<id_address_invoice>31754</id_address_invoice>
<id_cart>1314430</id_cart>
<id_currency>1</id_currency>
<id_lang>1</id_lang>
<id_customer>22578</id_customer>
<id_carrier>1</id_carrier>
<current_state>3</current_state>
<module>cashondelivery</module>
<invoice_number/>
<invoice_date/>
<delivery_number/>
<delivery_date/>
<valid>1</valid>
<date_add/>
<date_upd/>
<shipping_number/>
<id_shop_group/>
<id_shop/>
<secure_key/>
<payment>40862744-A</payment>
<recyclable/>
<gift/>
<gift_message/>
<mobile_theme/>
<total_discounts>0</total_discounts>
<total_discounts_tax_incl>0</total_discounts_tax_incl>
<total_discounts_tax_excl>0</total_discounts_tax_excl>
<total_paid>25.98</total_paid>
<total_paid_tax_incl>25.98</total_paid_tax_incl>
<total_paid_tax_excl>25.98</total_paid_tax_excl>
<total_paid_real>25.98</total_paid_real>
<total_products>1</total_products>
<total_products_wt>1</total_products_wt>
<total_shipping>2.99</total_shipping>
<total_shipping_tax_incl>2.99</total_shipping_tax_incl>
<total_shipping_tax_excl>2.99</total_shipping_tax_excl>
<carrier_tax_rate/>
<total_wrapping/>
<total_wrapping_tax_incl/>
<total_wrapping_tax_excl/>
<round_mode/>
<conversion_rate>1</conversion_rate>
<reference/>
<associations>
<order_rows>
<order_row>
<id/>
<product_id>233154</product_id>
<product_attribute_id>0</product_attribute_id>
<product_quantity>1</product_quantity>
<product_name>Smartwatch Gt08 Sim sd bluetooth Negro plata</product_name>
<product_reference>8435338885678</product_reference>
<product_ean13/>
<product_upc/>
<product_price>25.920000</product_price>
<unit_price_tax_incl>25.920000</unit_price_tax_incl>
<unit_price_tax_excl>25.920000</unit_price_tax_excl>
</order_row>
</order_rows>
</associations>
</order>
</prestashop>
RETURN HTTP BODY
**Here is blank space, don't know if there will be some response xml code...
Try setting these to an empty string. If that doesn't work try setting it to your product ID.
$xml->order->associations->order_rows->order_row[$i]->product_attribute_id
and
$xml->cart->associations->cart_rows->cart_row[$i]->id_product_attribute
Using this package for laravel: https://github.com/nikolajlovenhardt/laravel-google-ads
When i try to write a campaign, the following error occur:
SoapFault in AdsSoapClient.php line 115: Unmarshalling Error:
cvc-elt.4.3: Type 'ns1:Budget' is not validly derived from the type
definition, 'Campaign', of element 'ns1:operand'.
soap.log: http://pastebin.com/raw/TmU6XSfp
[2017-03-10 14:33:57] AW_SOAP.INFO: clientCustomerId=556-905-2150
operations=1 service=BudgetService method=mutate responseTime=145
requestId=00054a61407809890a378107c00d151f server=adwords.google.com
isFault=0 faultMessage= [2017-03-10 14:33:58] AW_SOAP.WARNING:
clientCustomerId=556-905-2150 operations= service=CampaignService
method=mutate responseTime= requestId= server=adwords.google.com
isFault=1 faultMessage=Unmarshalling Error: cvc-elt.4.3: Type
'ns1:Budget' is not validly derived from the type definition,
'Campaign', of element 'ns1:operand'. [2017-03-10 14:33:58]
AW_SOAP.NOTICE: POST /api/adwords/cm/v201609/CampaignService?wsdl
HTTP/1.1 Host: adwords.google.com Connection: Keep-Alive User-Agent:
PHP-SOAP/7.1.2-3+deb.sury.org~xenial+1 Content-Type: text/xml;
charset=utf-8 SOAPAction: "" Content-Length: 1436 Authorization:
REDACTED
556-905-2150REDACTEDunknown
(AwApi-PHP, googleads-php-lib/25.2.0,
PHP/7.1.2-3+deb.sury.org~xenial+1)falsefalseADDInterplanetary Cruise Budget
58c2b955417e250000000STANDARDADDInterplanetary Cruise
58c2b955cc997PAUSED1050511653DISPLAYMANUAL_CPC
HTTP/1.1 500 Internal Server Error Content-Type: text/xml;
charset=UTF-8 Date: Fri, 10 Mar 2017 14:33:58 GMT Expires: Fri, 10 Mar
2017 14:33:58 GMT Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block Server: GSE Alt-Svc: quic=":443";
ma=2592000; v="36,35,34" Accept-Ranges: none Vary: Accept-Encoding
Transfer-Encoding: chunked
soap:ClientUnmarshalling
Error: cvc-elt.4.3: Type 'ns1:Budget' is not validly derived from the
type definition, 'Campaign', of element 'ns1:operand'.
Copied from the "Basic Operations Samples"
$customerClientId = 'xxx-xxx-xxxx';
$adWordsService = new AdWordsService();
/** #var BudgetService $budgetService */
$budgetService = $adWordsService->getService(BudgetService::class, $customerClientId);
// Create the shared budget (required).
$budget = new Budget();
$budget->setName('Interplanetary Cruise Budget #' . uniqid());
$money = new Money();
$money->setMicroAmount(50000000);
$budget->setAmount($money);
$budget->setDeliveryMethod(BudgetBudgetDeliveryMethod::STANDARD);
$operations = [];
// Create a budget operation.
$operation = new BudgetOperation();
$operation->setOperand($budget);
$operation->setOperator(Operator::ADD);
$operations[] = $operation;
// Create the budget on the server.
$result = $budgetService->mutate($operations);
$budget = $result->getValue()[0];
// Create a campaign with only required settings.
$campaign = new Campaign();
$campaign->setName('Interplanetary Cruise #' . uniqid());
$campaign->setAdvertisingChannelType(AdvertisingChannelType::DISPLAY);
// Set shared budget (required).
$campaign->setBudget(new Budget());
$campaign->getBudget()->setBudgetId($budget->getBudgetId());
// Set bidding strategy (required).
$biddingStrategyConfiguration = new BiddingStrategyConfiguration();
$biddingStrategyConfiguration->setBiddingStrategyType(
BiddingStrategyType::MANUAL_CPC);
$campaign->setBiddingStrategyConfiguration($biddingStrategyConfiguration);
$campaign->setStatus(CampaignStatus::PAUSED);
// Create a campaign operation and add it to the operations list.
$operation = new CampaignOperation();
$operation->setOperand($campaign);
$operation->setOperator(Operator::ADD);
$operations[] = $operation;
/** #var CampaignService $campaignService */
$campaignService = $adWordsService->getService(CampaignService::class, $customerClientId);
$result = $campaignService->mutate($operations);
foreach ($result->getValue() as $campaign) {
printf("Campaign with name '%s' and ID %d was added.\n",
$campaign->getName(),
$campaign->getId()
);
}
Receiving campaigns with the sample code works...
I fink, it's because, you make $campaignService->mutate($operations); with budget operation
$operations = [];
// Create a budget operation.
$operation = new BudgetOperation();
$operation->setOperand($budget);
$operation->setOperator(Operator::ADD);
$operations[] = $operation;
And
// Create a campaign operation and add it to the operations list.
$operation = new CampaignOperation();
$operation->setOperand($campaign);
$operation->setOperator(Operator::ADD);
$operations[] = $operation;
$result = $campaignService->mutate($operations);
You need to do $operations = []; again before $campaignService->mutate($operations);
$operations = [];
// Create a campaign operation and add it to the operations list.
$operation = new CampaignOperation();
$operation->setOperand($campaign);
$operation->setOperator(Operator::ADD);
$operations[] = $operation;
/** #var CampaignService $campaignService */
$campaignService = $adWordsService->getService(CampaignService::class, $customerClientId);
$result = $campaignService->mutate($operations);
I try to use PayPal Reference Transactin. I have already made a billing agreemet, got the Billing Agreement ID set up before any transaction is done.
I make a simple transaction request, but got:
PPConnectionException in PPHttpConnection.php line 108:
Got Http response code 400 when accessing
https://api-3t.sandbox.paypal.com/2.0.
My code (writte in Laravel 5.3 with merchant-sdk-php package):
$user=Auth::user();
$currencyCode = 'GBP';
$price=config('constants.offer_submit_price');
$reference_id=$user->userExt()->where('field_name', '=', 'billing_agreement')->firstOrFail()->field_value;
$amount = new BasicAmountType($currencyCode, $price);
$paymentDetails = new PaymentDetailsType();
$paymentDetails->OrderTotal = $amount;
$RTRequestDetails = new DoReferenceTransactionRequestDetailsType();
$RTRequestDetails->PaymentDetails = $paymentDetails;
$RTRequestDetails->ReferenceID = $reference_id;
$RTRequestDetails->PaymentAction ='sale';
$RTRequest = new DoReferenceTransactionRequestType();
$RTRequest->DoReferenceTransactionRequestDetails = $RTRequestDetails;
$RTReq = new DoReferenceTransactionReq();
$RTReq->DoReferenceTransactionRequest = $RTRequest;
$paypalService = new PayPalAPIInterfaceServiceService($this->config);
try {
$setRTResponse = $paypalService->DoReferenceTransaction($RTReq);
} catch (Exception $ex) {
dd($ex);
}
Thats the SAOP envelopr produced by script:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="urn:ebay:api:PayPalAPI" xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:cc="urn:ebay:apis:CoreComponentTypes" xmlns:ed="urn:ebay:apis:EnhancedDataTypes" >
<soapenv:Header>
<ns:RequesterCredentials>
<ebl:Credentials>
<ebl:Username>username
</ebl:Username>
<ebl:Password>password
</ebl:Password>
<ebl:Signature>signature
</ebl:Signature>
</ebl:Credentials>
</ns:RequesterCredentials>
</soapenv:Header>
<soapenv:Body>
<ns:DoReferenceTransactionReq>
<ns:DoReferenceTransactionRequest>
<ebl:DoReferenceTransactionRequestDetails>
<ebl:ReferenceID>B-reference_id
</ebl:ReferenceID>
<ebl:PaymentAction>sale
</ebl:PaymentAction>
<ebl:PaymentDetails>
<ebl:OrderTotal currencyID="GBP">10
</ebl:OrderTotal>
<ebl:ButtonSource>PayPal_SDK
</ebl:ButtonSource>
</ebl:PaymentDetails>
</ebl:DoReferenceTransactionRequestDetails>
<ebl:Version>106.0
</ebl:Version>
</ns:DoReferenceTransactionRequest>
</ns:DoReferenceTransactionReq>
</soapenv:Body>
</soapenv:Envelope>'
With help of my friend I have figured out what was wrong.
$RTRequestDetails->PaymentAction ='Sale';
instead of
$RTRequestDetails->PaymentAction ='sale';
PayPal SOAP API need to have everything in right case sensitive.
Regret, they don't send any info what's wrong.
I am not familiar with SOAP webservices and I need to send a request to one.
I wrote the next snippet:
# WSDL http://webservices.sathomologa.sef.sc.gov.br/wsDfeSiv/Recepcao.asmx?WSDL
$this->client = new SoapClient(static::SERVICE_WSDL, ['exceptions' => 0]);
# Raw XML data
$data = $this->xml->saveXML();
# URL http://webservices.sathomologa.sef.sc.gov.br/wsDfeSiv/Recepcao.asmx
$location = static:SERVICE_URL;
$action = static::SERVICE_URL . '?op=Enviar';
$v = SOAP_1_1;
$response = $this->client->__doRequest($data, $location, $action, $v);
And I get the next test response:
soap:ClientServer did not recognize the value of HTTP Header
SOAPAction:
http://webservices.sathomologa.sef.sc.gov.br/wsDfeSiv/Recepcao.asmx?op=Enviar.
Any ideas?
Reading the specification of Enviar method, i saw the next header:
SOAPAction: "http://tempuri.org/Enviar"
So, i changed $action = static::SERVICE_URL . '?op=Enviar'; to $action = http://tempuri.org/Enviar; and works for me.
I am trying to create a script to receive POST from FoxyCart's Order Desk. I setup a temporary request bin at requestb.in. When I pointed the POST there I get the new order JSON fine. I copy/pasted the JSON string in my script with this code I was able to parse the JSON and successfully added the variables to my database:
$string = "{"id":"1191583","email":"office#burntimpressions.com","shipping_method":"","quantity_total":1,"weight_total":0,"product_total":0,"shipping_total":0,"handling_total":0,"tax_total":0,"discount_total":0,"order_total":0,"cc_number_masked":"","cc_exp":"","processor_response":"","payment_type":"","payment_status":"Approved","processor_balance":0,"customer_id":"","email_count":"1","ip_address":"71.161.83.59","tag_color":"","source_name":"Order Desk","source_id":"1191583","fulfillment_name":"","fulfillment_id":"","tag_name":"","folder_id":6814,"date_added":"2015-06-14 16:53:54","date_updated":"2015-06-14 16:54:27","shipping":{"first_name":"Galen","last_name":"Dively","company":"Vermont Novelty Toaster Corporation","address1":"136 Bay Street","address2":"Ste 2","address3":"","address4":"","city":"Saint Johnsbury","state":"Vermont","postal_code":"05819","country":"US","phone":"(916) 448-5517"},"customer":{"first_name":"Galen","last_name":"Dively","company":"Vermont Novelty Toaster Corporation","address1":"136 Bay Street","address2":"Ste 2","city":"Saint Johnsbury","state":"Vermont","postal_code":"05819","country":"US","phone":"(916) 448-5517"},"checkout_data":[],"order_metadata":[],"discount_list":[],"order_notes":[],"order_items":[{"id":"2090400","name":"selfie test","price":0,"quantity":1,"weight":0,"code":"selfie","delivery_type":"ship","category_code":"","variation_list":[],"metadata":[]}],"order_shipments":[]}";
$order = json_decode($string, true);
$transactionId = $order [id];
$firstName = $order[customer][first_name];
foreach($order [order_items] as $p)
{
$cid = $p[id];
$productName = $p[name];
$code = $p[code];
$quantity = $p[quantity];
}
Order Desk's documentation says to get the POST with this:
$order = json_decode($_POST['order'], 1);
I am not getting anything. I have tried just about everything I can think of. Looked through this forum and have found nothing that will get the JSON parsed. I am assuming the POST was successful because I am not getting any errors from Order Desk's admin panel.
Order Desk has this code for security purposes. The POST seemed to pass all of them.
<?php
//Check For Order
if (!isset($_POST['order'])) {
header(':', true, 400);
die('No Data Found');
}
//Cbeck Store ID
//Be sure to set your store ID. Ask Order Desk support if you aren't sure what it is.
if (!isset($_SERVER['HTTP_X_ORDER_DESK_STORE_ID']) || $_SERVER['HTTP_X_ORDER_DESK_STORE_ID'] != "YOUR-STORE-ID") {
header(':', true, 403);
die('Unauthorized Request');
}
//Check the Hash (optional)
//The API Key can be found in the Advanced Settings section. Order Desk Pro only
if (!isset($_SERVER['HTTP_X_ORDER_DESK_HASH']) || hash_hmac('sha256', rawurldecode($_POST['order']), 'YOUR_API_KEY') != $_SERVER['HTTP_X_ORDER_DESK_HASH']) {
header(':', true, 403);
die('Unauthorized Request');
}
//Check Order Data
$order = json_decode($_POST['order'], 1);
if (!is_array($order)) {
header(':', true, 400);
die('Invalid Order Data');
}
//Everything Checks Out -- do your thing
echo "<pre>" . print_r($order, 1) . "</pre>";
Any help is greatly appreciated!
I guess I am asking how you would parse:
$order = json_decode($_POST['order'], 1);
What I get from requestb.in :
FORM/POST PARAMETERS
order: {"id":"1191583","email":"office#burntimpressions.com","shipping_method":"","quantity_total":1,"weight_total":0,"product_total":0,"shipping_total":0,"handling_total":0,"tax_total":0,"discount_total":0,"order_total":0,"cc_number_masked":"","cc_exp":"","processor_response":"","payment_type":"","payment_status":"Approved","processor_balance":0,"customer_id":"","email_count":"1","ip_address":"71.161.83.59","tag_color":"","source_name":"Order Desk","source_id":"1191583","fulfillment_name":"","fulfillment_id":"","tag_name":"","folder_id":6814,"date_added":"2015-06-14 16:53:54","date_updated":"2015-06-14 16:54:27","shipping":{"first_name":"Galen","last_name":"Dively","company":"Vermont Novelty Toaster Corporation","address1":"136 Bay Street","address2":"Ste 2","address3":"","address4":"","city":"Saint Johnsbury","state":"Vermont","postal_code":"05819","country":"US","phone":"(916) 448-5517"},"customer":{"first_name":"Galen","last_name":"Dively","company":"Vermont Novelty Toaster Corporation","address1":"136 Bay Street","address2":"Ste 2","city":"Saint Johnsbury","state":"Vermont","postal_code":"05819","country":"US","phone":"(916) 448-5517"},"checkout_data":[],"order_metadata":[],"discount_list":[],"order_notes":[],"order_items":[{"id":"2090400","name":"selfie test","price":0,"quantity":1,"weight":0,"code":"selfie","delivery_type":"ship","category_code":"","variation_list":[],"metadata":[]}],"order_shipments":[]}
HEADERS
Total-Route-Time: 0
Connect-Time: 1
X-Request-Id: 26eb3b73-bd15-4d75-9605-ea4fda0191dd
User-Agent: Guzzle/5.3.0 curl/7.19.7 PHP/5.5.21
X-Order-Desk-Store-Id: XXXXXXX
Content-Type: application/x-www-form-urlencoded
Connection: close
Content-Length: 2228
Via: 1.1 vegur
Host: requestb.in
X-Order-Desk-Hash: XXXXXXXXXXXXX