I am working on this FedEx web service integration project for some time. I am using PHP to make calls to the FedEx server. Everything seems to be working properly.
But I am having problems with CustomerReferences fields appearing in the original fedex request that is sent to the server. I am using the ShipService_v7.wsdl. I asked FedEx tech support saying that would not be able to help with PHP code. But my problem is even the sample code provided by fedex is not able to generate the customerreferences fields in the request sent to the server.
Would you guys happen to know whats the deals with this?
EDIT:
Code that is generating the XML file being sent to the fedex web server,
$client = new SoapClient($path_to_wsdl, array('trace' => 1)); // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
$request['WebAuthenticationDetail'] = array('UserCredential' =>
array('Key' => $DEVELOPER_KEY, 'Password' => $DEVELOPER_PASSWORD)); // Replace 'XXX' and 'YYY' with FedEx provided credentials
$request['ClientDetail'] = array('AccountNumber' => $FEDEX_ACCOUNT_NUMBER, 'MeterNumber' => $FEDEX_METER_NUMBER);// Replace 'XXX' with your account and meter number
$request['TransactionDetail'] = array('CustomerTransactionId' => '*** Ground International Shipping Request v7 using PHP ***');
$request['Version'] = array('ServiceId' => 'ship', 'Major' => '7', 'Intermediate' => '0', 'Minor' => '0');
$request['RequestedShipment'] = array('ShipTimestamp' => date('c'),
'DropoffType' => 'REGULAR_PICKUP', // valid values REGULAR_PICKUP, REQUEST_COURIER, DROP_BOX, BUSINESS_SERVICE_CENTER and STATION
'ServiceType' => 'FEDEX_GROUND', // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
'PackagingType' => 'YOUR_PACKAGING', // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
'Shipper' => array('Contact' => array('PersonName' => 'Sender Name',
'CompanyName' => 'Company Name',
'PhoneNumber' => '0805522713'),
'Address' => array('StreetLines' => array('Address Line 1'),
'City' => 'Memphis',
'StateOrProvinceCode' => 'TN',
'PostalCode' => '38110',
'CountryCode' => 'US')),
'Recipient' => array('Contact' => array('PersonName' => 'Recipient Name',
'CompanyName' => 'Company Name',
'PhoneNumber' => '9012637906'),
'Address' => array('StreetLines' => array('Address Line 1'),
'City' => 'Richmond',
'StateOrProvinceCode' => 'BC',
'PostalCode' => 'V7C4V4',
'CountryCode' => 'CA',
'Residential' => false)),
'ShippingChargesPayment' => array('PaymentType' => 'SENDER', // valid values RECIPIENT, SENDER and THIRD_PARTY
'Payor' => array('AccountNumber' => $FEDEX_ACCOUNT_NUMBER, // Replace 'XXX' with payors account number
'CountryCode' => 'US')),
'InternationalDetail' => array('DutiesPayment' => array('PaymentType' => 'SENDER', // valid values RECIPIENT, SENDER and THIRD_PARTY
'Payor' => array('AccountNumber' => $FEDEX_ACCOUNT_NUMBER, // Replace 'XXX' with payor's account number
'CountryCode' => 'CA')),
'DocumentContent' => 'DOCUMENTS_ONLY',
'CustomsValue' => array('Amount' => 100.0, 'Currency' => 'USD'),
'Commodities' => array('0' => array('NumberOfPieces' => 1,
'Description' => 'Books',
'CountryOfManufacture' => 'US',
'Weight' => array('Value' => 1.0, 'Units' => 'LB'),
'Quantity' => 1,
'QuantityUnits' => 'EA',
'UnitPrice' => array('Amount' => 1.000000, 'Currency' => 'USD'),
'CustomsValue' => array('Amount' => 100.000000, 'Currency' => 'USD'))),
'ExportDetail' => array('B13AFilingOption' => 'FILED_ELECTRONICALLY')),
'LabelSpecification' => array('LabelFormatType' => 'COMMON2D', // valid values COMMON2D, LABEL_DATA_ONLY
'ImageType' => 'PNG', // valid values DPL, EPL2, PDF, ZPLII and PNG
'LabelStockType' => 'PAPER_7X4.75'),
'RateRequestTypes' => array('ACCOUNT'), // valid values ACCOUNT and LIST
'PackageCount' => 1,
'PackageDetail' => 'INDIVIDUAL_PACKAGES',
'RequestedPackageLineItems' => array('SequenceNumber' => 1,
'Weight' => array('Value' => 20.0, 'Units' => 'LB')), // valid values LB and KG
'CustomerReferences' => array('0' => array('CustomerReferenceType' => 'CUSTOMER_REFERENCE', 'Value' => 'TC007_07_PT1_ST01_PK01_SNDUS_RCPCA_POS')));
Expected Output :
... XML Stuff ...
<ns1:RequestedPackageLineItems>
<ns1:SequenceNumber>1</ns1:SequenceNumber>
<ns1:Weight>
<ns1:Units>LB</ns1:Units>
<ns1:Value>20</ns1:Value>
</ns1:Weight>
<ns1:CustomerReferences>
<ns1:CustomerReferenceType>CUSTOMER_REFERENCE</ns1:CustomerReferenceType>
<ns1:Value>I am a customer reference</ns1:Value>
</ns1:CustomerReferences>
</ns1:RequestedPackageLineItems>
... XML Stuff ...
Current Output
<ns1:RequestedPackageLineItems>
<ns1:SequenceNumber>1</ns1:SequenceNumber>
<ns1:Weight>
<ns1:Units>LB</ns1:Units>
<ns1:Value>20</ns1:Value>
</ns1:Weight>
</ns1:RequestedPackageLineItems>
add customer reference under addPackageLineItem1
like this:
'Dimensions' => array(
'Length' => 20,
'Width' => 20,
'Height' => 10,
'Units' => 'IN'),
'CustomerReferences' => array(
'0' => array(
'CustomerReferenceType' => 'CUSTOMER_REFERENCE',
'Value' => '123456'
))
Related
The below code is not rendering the line_items as a JSON array and I have searched/asked around to no avail.
Can anyone give me a hand here?
I've also included the json_encode data of the $orderShippingInfo variable.
Below is the JSON output:
{
"token":"API_KEY_HERE",
"email":"a.pinochet#chilehelicoptertours.com",
"line_items":{
"sku":"12345",
"name":"Product Name",
"title":"Product Title",
"price":"$1.99",
"quantity":"1",
"total_tax":"$0.00"
},
"shipping_lines":{
"title":"UPS",
"price":"$0.00",
"method":"UPS 3 DAY",
"carrier":"UPS"
},
"order_id":"0001",
"profile":"default",
"shipping_address":{
"province":"AZ",
"city":"Testville",
"first_name":"Augusto",
"last_name":"Pinochet",
"zip":"12341",
"province_code":"NY",
"country":"US",
"company":"Company Name, Inc.",
"phone":"1112223333",
"country_code":"US",
"address1":"123 Testing Dr Street",
"address2":"Suite #1"
},
"subtotal_price":"$0.00",
"created_at":"2017-02-02",
"country_code":"US",
"total_discounts":"$0.00",
"total_price":"$0.00"
}
TIA!
<?php
$orderShippingInfo = array(
'token' => 'API_KEY_HERE',
'email' => 'a.pinochet#chilehelicoptertours.com',
'line_items' => array(
'sku'=>'12345',
'name'=>'Product Name',
'title'=>'Product Title',
'price'=> '$1.99',
'quantity' => '1',
'total_tax' => '$0.00',
),
'shipping_lines' => array(
'title' => 'UPS',
'price' => '$0.00',
'method' => 'UPS 3 DAY',
'carrier' => 'UPS',
),
'order_id' => '0001',
'profile' => 'default',
'shipping_address' => array(
'province' => 'AZ',
'city' => 'Testville',
'first_name' => 'Augusto',
'last_name' => 'Pinochet',
'zip' => '12341',
'province_code' => 'NY',
'country' => 'US',
'company' => 'Company Name, Inc.',
'phone' => '1112223333',
'country_code' => 'US',
'address1' => '123 Testing Dr Street',
'address2' => 'Suite #1',
),
'subtotal_price' => '$0.00',
'created_at' => date('Y-m-d'),
'country_code' => 'US',
'total_discounts' => '$0.00',
'total_price' => '$0.00',
);
echo json_encode($orderShippingInfo);
?>
You need to make your array of line items an array of them.
For example:
$orderShippingInfo = array(
'token' => 'API_KEY_HERE',
'email' => 'a.pinochet#chilehelicoptertours.com',
'line_items' => array(
array(
'sku'=>'12345',
'name'=>'Product Name',
'title'=>'Product Title',
'price'=> '$1.99',
'quantity' => '1',
'total_tax' => '$0.00',
)
),
'shipping_lines' => array(
'title' => 'UPS',
'price' => '$0.00',
'method' => 'UPS 3 DAY',
'carrier' => 'UPS',
),
'order_id' => '0001',
'profile' => 'default',
'shipping_address' => array(
'province' => 'AZ',
'city' => 'Testville',
'first_name' => 'Augusto',
'last_name' => 'Pinochet',
'zip' => '12341',
'province_code' => 'NY',
'country' => 'US',
'company' => 'Company Name, Inc.',
'phone' => '1112223333',
'country_code' => 'US',
'address1' => '123 Testing Dr Street',
'address2' => 'Suite #1',
),
'subtotal_price' => '$0.00',
'created_at' => date('Y-m-d'),
'country_code' => 'US',
'total_discounts' => '$0.00',
'total_price' => '$0.00',
);
Then you can add a second line item to the array if you require.
The reason for this is that javascript does not have an associative array concept, so to produce one out of a json_encode() would break javascript.
See this example of what json_encode will do
$xx = ['a','b'];
$yy = ['one'=> 1, 'two'=>2];
print_r($xx);
echo json_encode($xx).PHP_EOL;
print_r($yy);
echo json_encode($yy);
Array
(
[0] => a
[1] => b
)
["a","b"] // note this is a JSON array
Array
(
[one] => 1
[two] => 2
)
{"one":1,"two":2} // note this is a JSON object
If the PHP array is numerically indexed, you get a JSON array
If the PHP array is assoc array it will create an JSON Object
If for some reason you specifically want a JSON String representation to be an array you could just add a [] to the $orderShippingInfo[] = array( like this
$orderShippingInfo[] = array(
'token' => 'API_KEY_HERE',
'email' => 'a.pinochet#chilehelicoptertours.com',
'line_items' => array(
'sku'=>'12345',
'name'=>'Product Name',
'title'=>'Product Title',
'price'=> '$1.99',
. . .
. . .
I am using this GitHub code for hotel listing and hotel details section https://github.com/dyatlov/Expedia-PHP-API
for the booking process i am using this code:
$info = $expedia->getHotelInfo( $_REQUEST['hotelid'] );
echo '<pre>';
var_export( $info );
// book hotel
$expedia->set_method('POST');
$expedia->set_protocol('https://book.');
$result = $expedia->res( array(
'hotelId' => $_REQUEST['hotelid'],
'arrivalDate' => '7/27/2015',
'departureDate' => '7/29/2015',
'supplierType' => 'E',
'rateKey' => '234be234234afd',
'roomTypeCode' => 12345,
'rateCode' => '123123',
'chargeableRate' => '150.0',
'room1' => 1,
'room1FirstName' => 'John',
'room1LastName' => 'Guest',
'room1BedTypeId' => 1234,
'room1SmokingPreference' => 'no',
'email' => 'test#test.com',
'firstName' => 'Tester',
'lastName' => 'Tester',
'homePhone' => '1234567',
'workPhone' => '1234567',
'creditCardType' => 'VI',
'creditCardNumber' => '41111111111111111',
'creditCardIdentifier' => '123',
'creditCardExpirationMonth' => '05',
'creditCardExpirationYear' => '2017',
'address1' => 'travelnow',
'city' => 'Moscow',
'stateProvinceCode' => null,
'countryCode' => 'RU',
'postalCode' => '3357'
) );
but here I integrate this code in the WordPress and from the request URL i will get the hotel id now please tell me what is specified process to make the onsite booking for Expedia and how can get the confirmation and also cancel acknowledgement.I am doing all this job in the development mode.
I have this code: http://pastebin.com/iFwyKM7G
Inside an event-observer class which executes after the customer registered. It creates an order automatically and it works for simple products. However I cannot figure out for the life of me how to make it work with Bundled product!
How can I make this work with a bundled product?
I DID IT!
I changed my code to the following:
$customer = Mage::getSingleton('customer/customer')->load($observer->getCustomer()->getId());
$session = Mage::getSingleton('adminhtml/session_quote');
$order_create_model = Mage::getSingleton('adminhtml/sales_order_create');
Mage::log($customer->debug(), null, 'toszodj_meg.log');
//$transaction = Mage::getModel('core/resource_transaction');
$storeId = $customer->getStoreId();
Mage::log($customer->getDefaultBillingAddress()->debug(), null, 'toszodj_meg.log');
$reservedOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($storeId);
$session->setCustomerId((int) $customer->getId());
$session->setStoreId((int) $storeId);
$orderData = array(
'session' => array(
'customer_id' => $customer->getId(),
'store_id' => $storeId,
),
'payment' => array(
'method' => 'banktransfer',
'po_number' => (string) '-',
),
// 123456 denotes the product's ID value
'add_products' =>array(
'2' => array(
'qty' => 1,
'bundle_option' => array(
2 => 2,
1 => 1,
),
'bundle_option_qty' => array(
2 => 1,
1 => 1,
),
),
),
'order' => array(
'currency' => 'EUR',
'account' => array(
'group_id' => $customer->getGroupId(),
'email' => (string) $customer->getEmail(),
),
'comment' => array('customer_note' => 'API ORDER'),
'send_confirmation' => 1,
'shipping_method' => 'flatrate_flatrate',
'billing_address' => array(
'customer_address_id' => $customer->getDefaultBillingAddress()->getEntityId(),
'prefix' => $customer->getDefaultBillingAddress()->getPrefix(),
'firstname' => $customer->getDefaultBillingAddress()->getFirstname(),
'middlename' => $customer->getDefaultBillingAddress()->getMiddlename(),
'lastname' => $customer->getDefaultBillingAddress()->getLastname(),
'suffix' => $customer->getDefaultBillingAddress()->getSuffix(),
'company' => $customer->getDefaultBillingAddress()->getCompany(),
'street' => $customer->getDefaultBillingAddress()->getStreet(),
'city' => $customer->getDefaultBillingAddress()->getCity(),
'country_id' => $customer->getDefaultBillingAddress()->getCountryId(),
'region' => $customer->getDefaultBillingAddress()->getRegion(),
'region_id' => $customer->getDefaultBillingAddress()->getRegionId(),
'postcode' => $customer->getDefaultBillingAddress()->getPostcode(),
'telephone' => $customer->getDefaultBillingAddress()->getTelephone(),
'fax' => $customer->getDefaultBillingAddress()->getFax(),
),
'shipping_address' => array(
'customer_address_id' => $customer->getDefaultShippingAddress()->getEntityId(),
'prefix' => $customer->getDefaultShippingAddress()->getPrefix(),
'firstname' => $customer->getDefaultShippingAddress()->getFirstname(),
'middlename' => $customer->getDefaultShippingAddress()->getMiddlename(),
'lastname' => $customer->getDefaultShippingAddress()->getLastname(),
'suffix' => $customer->getDefaultShippingAddress()->getSuffix(),
'company' => $customer->getDefaultShippingAddress()->getCompany(),
'street' => $customer->getDefaultShippingAddress()->getStreet(),
'city' => $customer->getDefaultShippingAddress()->getCity(),
'country_id' => $customer->getDefaultShippingAddress()->getCountryId(),
'region' => $customer->getDefaultShippingAddress()->getRegion(),
'region_id' => $customer->getDefaultShippingAddress()->getRegionId(),
'postcode' => $customer->getDefaultShippingAddress()->getPostcode(),
'telephone' => $customer->getDefaultShippingAddress()->getTelephone(),
'fax' => $customer->getDefaultShippingAddress()->getFax(),
),
),
);
$order_create_model->importPostData($orderData['order']);
$order_create_model->getBillingAddress();
$order_create_model->setShippingAsBilling(true);
$order_create_model->addProducts($orderData['add_products']);
$order_create_model->collectShippingRates();
$order_create_model->getQuote()->getPayment()->addData($orderData['payment']);
$order_create_model
->initRuleData()
->saveQuote();
$order_create_model->getQuote()->getPayment()->addData($orderData['payment']);
$order_create_model->setPaymentData($orderData['payment']);
$order_create_model
->importPostData($orderData['order'])
->createOrder();
$session->clear();
Mage::unregister('rule_data');
Mage::log('Order Successfull', null, 'siker_bammer.log');
And it works! thought the customer doesn't get notified. which iam trying to figure out now.
I'm trying to check the data that paypal sends to my notify_url after a transaction has been paid (in this case using the sandbox).
I've tried the sample code from paypal with fsockopen but I just couldn't get it to work properly. I also tried with cURL by manually giving a certificate, but it didn't turn out well either.
However after some changes, I managed to find a solution :
<?php
$_POST = array('mc_gross' => '9.90',
'protection_eligibility' => 'Eligible',
'address_status' => 'confirmed',
'payer_id' => '5PK5H93BE5RAQ',
'tax' => '0.00',
'address_street' => '1 Main St',
'payment_date' => '12:13:29 Jan 12, 2012 PST',
'payment_status' => 'Pending',
'charset' => 'windows-1252',
'address_zip' => '95131',
'first_name' => 'Test',
'address_country_code' => 'US',
'address_name' => 'Test User',
'notify_version' => '3.4',
'custom' => '523368657',
'payer_status' => 'verified',
'business' => 'seller_1326059109_biz#yahoo.fr',
'address_country' => 'United States',
'address_city' => 'San Jose',
'quantity' => '1',
'verify_sign' => 'AGilT0jx3itxd3XAujXRvUPipg93ATqSM88ML-PAwAoa7xGkRSWXhVR8',
'payer_email' => 'buyer_1326398444_per#yahoo.fr',
'txn_id' => '1C254380JG793833D',
'payment_type' => 'instant',
'last_name' => 'User',
'address_state' => 'CA',
'receiver_email' => 'seller_1326059109_biz#yahoo.fr',
'receiver_id' => 'FKBDH7FDLECEQ',
'pending_reason' => 'multi_currency',
'txn_type' => 'web_accept',
'item_name' => 'Compte premium winker',
'mc_currency' => 'EUR',
'item_number' => '',
'residence_country' => 'US',
'test_ipn' => '1',
'handling_amount' => '0.00',
'transaction_subject' => '523368657',
'payment_gross' => '',
'shipping' => '0.00',
'ipn_track_id' => '1v3OWX6MBMqE6Oe6-BSmCA');
$req = '?cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$url = 'https://sandbox.paypal.com/cgi-bin/webscr'.$req;
echo '<p>browse link</p>';
$content = file_get_contents($url);
var_dump($content);
I do get a result but it is "INVALID", whereas if I open the link on my browser (with the exact same informations), it is "VERIFIED" !
Any ideas ?
Thanks in advance for your replies
I am getting PayPal's IPN in array form like this:
$ipn = array(
'mc_gross' => '15.50',
'protection_eligibility' => 'Eligible',
'address_status' => 'confirmed',
'item_number1' => '1',
'tax' => '0.00',
'item_number2' => '2',
'payer_id' => 'XXXXXXXXXXXXX',
'address_street' => '1 Main St',
'payment_date' => '02:41:18 Nov 23, 2011 PST',
'payment_status' => 'Completed',
'charset' => 'windows-1252',
'address_zip' => '95131',
'mc_shipping' => '0.00',
'mc_handling' => '0.00',
'first_name' => 'Test',
'mc_fee' => '0.75',
'address_country_code' => 'US',
'address_name' => 'Test User',
'custom' => '',
'payer_status' => 'verified',
'business' => 'receiver#example.com',
'address_country' => 'United States',
'num_cart_items' => '2',
'mc_handling1' => '0.00',
'mc_handling2' => '0.00',
'address_city' => 'San Jose',
'payer_email' => 'payer#example.com',
'mc_shipping1' => '0.00',
'mc_shipping2' => '0.00',
'txn_id' => '8RE82733S8684874F',
'payment_type' => 'instant',
'last_name' => 'User',
'address_state' => 'CA',
'item_name1' => 'trilogy2',
'receiver_email' => 'receiver#example.com',
'item_name2' => 'trilogy1',
'payment_fee' => '0.75',
'quantity1' => '1',
'quantity2' => '1',
'receiver_id' => 'XXXXXXXXXXXXX',
'txn_type' => 'cart',
'mc_gross_1' => '5.55',
'mc_currency' => 'USD',
'mc_gross_2' => '9.95',
'residence_country' => 'US',
'transaction_subject' => 'Shopping Carttrilogy2trilogy1',
'payment_gross' => '15.50',
'' => ''
);
In this case customer has ordered only 2 items: 'item_name1' and 'item_name2'
Obviously, a customer can order X number of products and PayPal will include an 'item_nameX' in the notification data. Is there a way to go through the array and extract all names and assign them to variables so I will have something like:
$ordered_item1 = $ipn['item_name1'];
$ordered_item2 = $ipn['item_name2'];
...
$ordered_itemXYZ = $ipn['item_nameXYZ'];
Thanks for any help.
If you have data named with a prefix followed by a count, you should be using an array, not separate variables. To fill an array with the item information:
foreach ($ipn as $key => $value) {
if (preg_match('/(?P<field>[a-z]+)_?(?P<i>\d+)/', $key, $parts)) {
$ordered_items[(int) $parts['i']][$parts['field']] = $value;
}
}