QuickBooks PHP API Add Payment Error - php

I'm trying to update a QB invoice with a payment using the PHP API by Keith Palmer. What I'm doing is:
1) Grab the invoice information (See code bellow)
2) Add a payment
Following this code example:
https://github.com/consolibyte/quickbooks-php/blob/master/docs/partner_platform/example_app_ipp_v3/example_payment_add.php
I've created this:
function updateQBInvoice($invoiceNumber = null, $depositAmount = null) {
$this->autoRender = false;
Configure::write('debug', 2);
include(APP."webroot".DS."quickbooks-php".DS."docs".DS."example_app_ipp_v3".DS."config.php");
$IPP = new QuickBooks_IPP($dsn);
$creds = $IntuitAnywhere->load($the_username, $the_tenant);
$IPP->authMode(QuickBooks_IPP::AUTHMODE_OAUTH, $the_username, $creds);
$realm = $creds['qb_realm'];
if ($Context = $IPP->context()) {
$IPP->version(QuickBooks_IPP_IDS::VERSION_3);
$InvoiceService = new QuickBooks_IPP_Service_Invoice();
$invoices = $InvoiceService->query($Context, $realm, "SELECT * FROM Invoice WHERE DocNumber='".$invoiceNumber."'");
$Invoice = $invoices[0];
$docNumber = $Invoice->getDocNumber();
$CustomerRef = $Invoice->getCustomerRef();
$invoiceId = $Invoice->getId();
$PaymentService = new QuickBooks_IPP_Service_Payment();
$Payment = new QuickBooks_IPP_Object_Payment();
$Payment->setPaymentRefNum($invoiceNumber);
$Payment->setTxnDate(date('Y-m-d'));
$Payment->setTotalAmt($depositAmount);
$Line = new QuickBooks_IPP_Object_Line();
$Line->setAmount($depositAmount);
$LinkedTxn = new QuickBooks_IPP_Object_LinkedTxn();
$LinkedTxn->setTxnId($invoiceId);
$LinkedTxn->setTxnType('Invoice');
$Line->setLinkedTxn($LinkedTxn);
$Payment->addLine($Line);
$Payment->setCustomerRef($CustomerRef);
debug($Payment);
if ($resp = $PaymentService->add($Context, $realm, $Payment)) {
print('Our new Payment ID is: [' . $resp . ']');
} else {
print($PaymentService->lastError());
}
debug('Request [' . $PaymentService->lastRequest() . ']');
debug('Response [' . $PaymentService->lastResponse() . ']');
} else {
echo 'Unable to load a context...?';
}
}
What I've noticed, when getting the invoice info is, all numbers are negatives, and if I assigned them to variable they are {-123}. My response is always:
2030: [Invalid ID, Id should be a valid number. Supplied value:{-10643}]
I imagine I'm setting something wrong somewhere. Would someone care to explain what I'm doing wrong please? Thanks!
UPDATE:
Request:
POST https://quickbooks.api.intuit.com/v3/company/210896252/payment HTTP/1.1
Content-Type: application/xml
Authorization: OAuth realm="", oauth_signature_method="HMAC-SHA1", oauth_signature="jxw2JuAGtvcg9ynRxXApi8VjcWk%3D", oauth_nonce="uvJB5", oauth_timestamp="1400786567", oauth_token="xxx", oauth_consumer_key="xxx", oauth_version="1.0"
Content-Length: 414
<Payment xmlns="http://schema.intuit.com/finance/v3">
<Line xmlns="http://schema.intuit.com/finance/v3">
<Amount>45</Amount>
<LinkedTxn xmlns="http://schema.intuit.com/finance/v3">
<TxnId>{-10643}</TxnId>
<TxnType>Invoice</TxnType>
</LinkedTxn>
</Line>
<PaymentRefNum>2060</PaymentRefNum>
<TxnDate>2014-05-22</TxnDate>
<TotalAmt>45</TotalAmt>
<CustomerRef>627</CustomerRef>
</Payment>
Response:
HTTP/1.1 400 Bad Request
Date: Thu, 22 May 2014 19:22:47 GMT
Content-Type: application/xml
Content-Length: 278
intuit_tid: c53e5e81-fd5e-4a24-b511-cd6b3449d012
Via: 1.1 ipp-gateway-.net
Vary: Accept-Encoding
Content-Encoding: gzip
Connection: close
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2014-05-22T12:22:47.834-07:00"><Fault type="ValidationFault"><Error code="2030" element="LinkedTxn.TxnId"><Message>Invalid ID</Message><Detail>Id should be a valid number. Supplied value:{-10643}</Detail></Error></Fault></IntuitResponse>

This highlights your problem here:
<LinkedTxn xmlns="http://schema.intuit.com/finance/v3">
<TxnId>0</TxnId>
<TxnType>Invoice</TxnType>
</LinkedTxn>
You're not setting a valid Id value for the transaction for some reason.
This is probably because of one of two reasons:
You're just not setting a valid TxnId in your code somewhere (if you print out print($Invoice->getId()); what do you see?)
OR
You're using an outdated version of the code from GitHub, which had a but related to this in it (make sure you're using the very latest code from GitHub, as of today)

Related

Prestahop Order Webservice Issue

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

Type 'ns1:Budget' is not validly derived from the type definition, 'Campaign', of element 'ns1:operand'

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);

PayPal reference transaction- status code 400 in response

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.

Unrecognized soap action

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.

Getting JSON $_POST from FoxyCart Order Desk

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

Categories