Unable to create Sales Order from JCO - sap

I am using the below code to call the BAPI BAPI_SALESORDER_CREATEFROMDAT2 to create the sales order . SAP machine is generating a SO number and sending as a response but when i check with va03 for the SO number which i have received sales order is not created .
If i do manually using va01 with the same data i can create the sales order successfully. Please need help on this .
public static void createSalesOrder() {
try {
JCoDestination destination = JCoDestinationManager.getDestination("ABAP_AS_WITH_POOL");
JCoFunction functionCreateOrder = destination.getRepository().getFunction("BAPI_SALESORDER_CREATEFROMDAT2");
//this is the bapi
JCoFunction functionTransComit = destination.getRepository().getFunction("BAPI_TRANSACTION_COMMIT");
JCoStructure orderHeaderIn = functionCreateOrder.getImportParameterList().getStructure("ORDER_HEADER_IN");
orderHeaderIn.setValue("SALES_ORG", "2000");//sales organisation
orderHeaderIn.setValue("DISTR_CHAN", "20");//distribution channel
orderHeaderIn.setValue("DIVISION", "20");// sales division
orderHeaderIn.setValue("DOC_TYPE", "ZAR");// document type
orderHeaderIn.setValue("PURCH_NO_C", "TEST123");
JCoTable orderPartners = functionCreateOrder.getTableParameterList().getTable("ORDER_PARTNERS");
// WE,AG,SP,PH
// AG Sold to Party
// WE Ship to Partyx
orderPartners.appendRow();
orderPartners.setValue("PARTN_ROLE", "AG");//partner role ag is sold to party
orderPartners.setValue("PARTN_NUMB", "0000000035");// partner number
orderPartners.appendRow();
orderPartners.setValue("PARTN_ROLE", "WE");//we is ship tp party
orderPartners.setValue("PARTN_NUMB", "0000000035");// partner number
System.out.println(orderPartners);
JCoTable orderItemsIn = functionCreateOrder.getTableParameterList().getTable("ORDER_ITEMS_IN");
orderItemsIn.appendRow();
orderItemsIn.setValue("MATERIAL", "PEN_ARN");// material
System.out.println(orderItemsIn);
JCoTable orderSchedulesIn = functionCreateOrder.getTableParameterList().getTable("ORDER_SCHEDULES_IN");
orderSchedulesIn.appendRow();
orderSchedulesIn.setValue("REQ_QTY", "10");// required quantity
System.out.println(orderSchedulesIn);
functionCreateOrder.execute(destination);
// System.out.println(functionCreateOrder);
JCoTable returnTable = functionCreateOrder.getTableParameterList().getTable("RETURN");
System.out.println(returnTable);
System.out.println(returnTable.getString("MESSAGE"));
System.out.println("sales order number is : "
+ functionCreateOrder.getExportParameterList().getValue("SALESDOCUMENT"));
functionTransComit.execute(destination);
} catch (JCoException ex) {
System.out.println(ex.getMessage());
} finally {
System.out.println("Creating sales order ends");
}
}

This depends on your JCo version, but at least with JCo 3 you need to execute your call to BAPI_TRANSACTION_COMMIT within the same context as your function call to BAPI_SALESORDER_CREATEFROMDAT2. Currently both calls are executed in individual contexts, so the second call to BAPI_TRANSACTION_COMMIT doesn't really commit anything. You have to create a context first:
JCoContext.begin(destination);
// execute both function calls to
// BAPI_SALESORDER_CREATEFROMDAT2 and
// BAPI_TRANSACTION_COMMIT
JCoContext.end(destination);

Related

Hangfire executes job twice

I am using Hangfire.AspNetCore 1.7.17 and Hangfire.MySqlStorage 2.0.3 for software that is currently in production.
Now and then, we get a report of jobs being executed twice, despite the usage of the [DisableConcurrentExecution] attribute with a timeout of 30 seconds.
It seems that as soon as those 30 seconds have passed, another worker picks up that same job again.
The code is fairly straightforward:
public async Task ProcessPicking(HttpRequest incomingRequest)
{
var filePath = await StoreStreamAsync(incomingRequest, TriggerTypes.Picking);
var picking = await XmlHelper.DeserializeFileAsync<Picking>(filePath);
// delay with 20 minutes so outbound-out gets the chance to be send first
BackgroundJob.Schedule(() => StartPicking(picking), TimeSpan.FromMinutes(20));
}
[TriggerAlarming("[IMPORTANT] Failed to parse picking message to **** object.")]
[DisableConcurrentExecution(30)]
public void StartPicking(Picking picking)
{
var orderlinePickModels = picking.ToSalesOrderlinePickQuantityRequests().ToList();
var orderlineStatusModels = orderlinePickModels.ToSalesOrderlineStatusRequests().ToList();
var isParsed = DateTime.TryParse(picking.Order.UnloadingDate, out var unloadingDate);
for (var i = 0; i < orderlinePickModels.Count; i++)
{
// prevents bugs with usage of i in the background jobs
var index = i;
var id = BackgroundJob.Enqueue(() => SendSalesOrderlinePickQuantityRequest(orderlinePickModels[index], picking.EdiReference));
BackgroundJob.ContinueJobWith(id, () => SendSalesOrderlineStatusRequest(
orderlineStatusModels.First(x=>x.SalesOrderlineId== orderlinePickModels[index].OrderlineId),
picking.EdiReference, picking.Order.PrimaryReference, isParsed ? unloadingDate : DateTime.MinValue));
}
}
[TriggerAlarming("[IMPORTANT] Failed to send order line pick quantity request to ****.")]
[AutomaticRetry(Attempts = 2)]
[DisableConcurrentExecution(30)]
public void SendSalesOrderlinePickQuantityRequest(SalesOrderlinePickQuantityRequest request, string ediReference)
{
var audit = new AuditPostModel
{
Description = $"Finished job to send order line pick quantity request for item {request.Itemcode}, part of ediReference {ediReference}.",
Object = request,
Type = AuditTypes.SalesOrderlinePickQuantity
};
try
{
_logger.LogInformation($"Started job to send order line pick quantity request for item {request.Itemcode}.");
var response = _service.SendSalesOrderLinePickQuantity(request).GetAwaiter().GetResult();
audit.StatusCode = (int)response.StatusCode;
if (!response.IsSuccessStatusCode) throw new TriggerRequestFailedException();
audit.IsSuccessful = true;
_logger.LogInformation("Successfully posted sales order line pick quantity request to ***** endpoint.");
}
finally
{
Audit(audit);
}
}
It schedules the main task (StartPicking) that creates the objects required for the two subtasks:
Send picking details to customer
Send statusupdate to customer
The first job is duplicated. Perhaps the second job as well, but this is not important enough to care about as it just concerns a statusupdate. However, the first job causes the customer to think that more items have been picked than in reality.
I would assume that Hangfire updates the state of a job to e.g. in progress, and checks this state before starting a job. Is my time-out on the disabled concurrent execution too low? Is it possible in this scenario that the database connection to update the state takes about 30 seconds (to be fair, it is running on a slow server with ~8GB Ram, 6 vCores) due to which the second worker is already picking up the job again?
Or is this a Hangfire specific issue that must be tackled?

Community Connector getData() Request only uses the first two schema fields, not all four

I am building a Community Connector between Google Data Studio and SpyFu.com, in order to funnel SEO information for a specific url into the GDS Dashboard.
However, My getData() request only contains the first two fields from my Schema. As you can see, I have four listed in the code. The result is only the first two fields in the schema are printed to GDS.
I've been through tutorials, official documentation, YouTube videos, looked this issue up on google and checked out the community resources on GitHub.
//Step Two: Define getConfig()
function getConfig(request) {
var cc = DataStudioApp.createCommunityConnector();
var config = cc.getConfig();
config.newInfo()
.setId('instructions')
.setText('Give me SpyFu information on the following domain:');
config.newTextInput()
.setId('domain')
.setName('Enter the domain to search')
.setHelpText('e.g. ebay.com')
.setPlaceholder('ebay.com');
config.newTextInput()
.setId('SECRET_KEY')
.setName('Enter your API Secret Key')
.setHelpText('e.g. A1B2C3D4')
.setPlaceholder('A1B2C3D4');
config.setDateRangeRequired(false);
return config.build();
}
//Step Three: Define getSchema()
function getFields(request) {
var cc = DataStudioApp.createCommunityConnector();
var fields = cc.getFields();
var types = cc.FieldType;
var aggregations = cc.AggregationType;
fields.newDimension()
.setId('Keyword')
.setName('Keywords')
.setDescription('The keywords most often attributed to this domain.')
.setType(types.TEXT);
fields.newMetric()
.setId('Rank')
.setName('Rankings')
.setDescription('The ranking of the target site keyword on the Google Search Page.')
.setType(types.NUMBER);
fields.newMetric()
.setId('Local_Monthly_Searches')
.setName('Local Searches per Month')
.setDescription('Number of times, locally, that people have searched for this term within in the last month.')
.setType(types.NUMBER);
fields.newMetric()
.setId('Global_Monthly_Searches')
.setName('Global Searches per Month')
.setDescription('Number of times, globally, that people have searched for this term within in the last month.')
.setType(types.NUMBER);
return fields;
}
function getSchema(request) {
var fields = getFields(request).build();
return { schema: fields };
}
//Step Four: Define getData()
function responseToRows(requestedFields, response, domain) {
// Transform parsed data and filter for requested fields
return response.map(function(Array) {
var row = [];
requestedFields.asArray().forEach(function (field) {
switch (field.getId()) {
case 'Keyword':
return row.push(Array.term);
case 'Rank':
return row.push(Array.position);
case 'Local_Monthly_Searches':
return row.push(Array.exact_local_monthly_search_volume);
case 'Global_Monthly_Searches':
return row.push(Array.exact_global_monthly_search_volume);
case 'domain':
return row.push(domain);
default:
return row.push('');
}
});
return { values: row };
});
}
function getData(request) {
console.log("Request from Data Studio");
console.log(request);
var requestedFieldIds = request.fields.map(function(field) {
return field.name;
});
var requestedFields = getFields().forIds(requestedFieldIds);
// Fetch data from API
var url = [
'https://www.spyfu.com/apis/url_api/organic_kws?q='
+ request.configParams.domain
+ '&r=20'
+ '&p=[1 TO 10]'
+ '&api_key='
+ request.configParams.SECRET_KEY,
];
try {
var response = UrlFetchApp.fetch(url.join(''));
} catch (e) {
DataStudioApp.createCommunityConnector()
.newUserError()
.setDebugText('Failed URL Fetch Attempt. Exception details: ' + e)
.setText('There was an error accessing this domain. Try again later, or file an issue if this error persists.')
.throwException();
}
console.log("Response from API");
console.log(response);
//Parse data from the API
try {
var parsedResponse = JSON.parse(response);
} catch (e) {
DataStudioApp.createCommunityConnector()
.newUserError()
.setDebugText('Error parsing the JSON data. Exception details: ' + e)
.setText('There was an error parsing the JSON data. Try again later, or file an issue if this error persists.')
.throwException();
}
var rows = responseToRows(requestedFields, parsedResponse);
return {
schema: requestedFields.build(),
rows: rows
};
}
I need the GDS to post four columns of data. They are, "Keyword", "Rank", "Local Monthly Searches" and "Global Monthly searches".
I cannot figure out how to create a "fixed schema" so that the system always prints these four columns of data at every request. The tutorials and various documentation say it's possible, but not how to do it. Please help!
The number of metrics initially called up by the Google Community Connector is handled from the front-end, via Google Data Studio.
The back-end system (the Connector) only initially posts the default dimension and default metric. Getting the rest of the schemas to post should be handled when you are building a report on Google Data Studio. Simply click on the data set, select "data" on the right-hand menu, scroll down to either Metrics or Dimensions, and pick the ones you wish to add to the current set.
Note that these are the fields you established earlier in the coding process, when you were setting up your schemas.
Here, you're filtering your defined schema for fields that are present on the request object received by getData().
var requestedFieldIds = request.fields.map(function(field) {
return field.name;
});
var requestedFields = getFields().forIds(requestedFieldIds);
The visualization in Google Data Studio that is the catalyst for the request will determine which fields are requested.

Paypal Php Sdk - NotifyUrl is not a fully qualified URL Error

I have this code
$product_info = array();
if(isset($cms['site']['url_data']['product_id'])){
$product_info = $cms['class']['product']->get($cms['site']['url_data']['product_id']);
}
if(!isset($product_info['id'])){
/*
echo 'No product info.';
exit();
*/
header_url(SITE_URL.'?subpage=user_subscription#xl_xr_page_my%20account');
}
$fee = $product_info['yearly_price_end'] / 100 * $product_info['fee'];
$yearly_price_end = $product_info['yearly_price_end'] + $fee;
$fee = ($product_info['setup_price_end'] / 100) * $product_info['fee'];
$setup_price_end = $product_info['setup_price_end'] + $fee;
if(isset($_SESSION['discountcode_amount'])){
$setup_price_end = $setup_price_end - $_SESSION['discountcode_amount'];
unset($_SESSION['discountcode_amount']);
}
$error = false;
$plan_id = '';
$approvalUrl = '';
$ReturnUrl = SITE_URL.'payment/?payment_type=paypal&payment_page=process_agreement';
$CancelUrl = SITE_URL.'payment/?payment_type=paypal&payment_page=cancel_agreement';
$now = $cms['date'];
$now->modify('+5 minutes');
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
$cms['options']['plugin_paypal_clientid'], // ClientID
$cms['options']['plugin_paypal_clientsecret'] // ClientSecret
)
);
use PayPal\Api\ChargeModel;
use PayPal\Api\Currency;
use PayPal\Api\MerchantPreferences;
use PayPal\Api\PaymentDefinition;
use PayPal\Api\Plan;
use PayPal\Api\Patch;
use PayPal\Api\PatchRequest;
use PayPal\Common\PayPalModel;
use PayPal\Api\Agreement;
use PayPal\Api\Payer;
use PayPal\Api\ShippingAddress;
// Create a new instance of Plan object
$plan = new Plan();
// # Basic Information
// Fill up the basic information that is required for the plan
$plan->setName($product_info['name'])
->setDescription($product_info['desc_text'])
->setType('fixed');
// # Payment definitions for this billing plan.
$paymentDefinition = new PaymentDefinition();
// The possible values for such setters are mentioned in the setter method documentation.
// Just open the class file. e.g. lib/PayPal/Api/PaymentDefinition.php and look for setFrequency method.
// You should be able to see the acceptable values in the comments.
$setFrequency = 'Year';
//$setFrequency = 'Day';
$paymentDefinition->setName('Regular Payments')
->setType('REGULAR')
->setFrequency($setFrequency)
->setFrequencyInterval("1")
->setCycles("999")
->setAmount(new Currency(array('value' => $yearly_price_end, 'currency' => $cms['session']['client']['currency']['iso_code'])));
// Charge Models
$chargeModel = new ChargeModel();
$chargeModel->setType('SHIPPING')
->setAmount(new Currency(array('value' => 0, 'currency' => $cms['session']['client']['currency']['iso_code'])));
$paymentDefinition->setChargeModels(array($chargeModel));
$merchantPreferences = new MerchantPreferences();
// ReturnURL and CancelURL are not required and used when creating billing agreement with payment_method as "credit_card".
// However, it is generally a good idea to set these values, in case you plan to create billing agreements which accepts "paypal" as payment_method.
// This will keep your plan compatible with both the possible scenarios on how it is being used in agreement.
$merchantPreferences->setReturnUrl($ReturnUrl)
->setCancelUrl($CancelUrl)
->setAutoBillAmount("yes")
->setInitialFailAmountAction("CONTINUE")
->setMaxFailAttempts("0")
->setSetupFee(new Currency(array('value' => $setup_price_end, 'currency' => $cms['session']['client']['currency']['iso_code'])));
$plan->setPaymentDefinitions(array($paymentDefinition));
$plan->setMerchantPreferences($merchantPreferences);
// ### Create Plan
try {
$output = $plan->create($apiContext);
} catch (Exception $ex){
die($ex);
}
echo $output->getId().'<br />';
echo $output.'<br />';
Been working with paypal php sdk for some days now and my code stop working.
So i went back to basic and i am still getting the same damn error.
I am trying to create a plan for subscription but getting the following error:
"NotifyUrl is not a fully qualified URL"
I have no idea how to fix this as i dont use NotfifyUrl in my code?
Could be really nice if anyone had an idea how to fix this problem :)
Thanks
PayPal did a update to their API last night which has caused problem within their SDK.
They are sending back null values in their responses.
I MUST stress the error is not on sending the request to PayPal, but on processing their response.
BUG Report : https://github.com/paypal/PayPal-PHP-SDK/issues/1151
Pull Request : https://github.com/paypal/PayPal-PHP-SDK/pull/1152
Hope this helps, but their current SDK is throwing exceptions.
Use below simple fix.
Replace below function in vendor\paypal\rest-api-sdk-php\lib\PayPal\Api\MerchantPreferences.php
public function setNotifyUrl($notify_url)
{
if(!empty($notify_url)){
UrlValidator::validate($notify_url, "NotifyUrl");
}
$this->notify_url = $notify_url;
return $this;
}
If you get the same error for return_url/cancel_url, add the if condition as above.
Note: This is not a permanent solution, you can use this until getting the update from PayPal.
From the GitHub repo for the PayPal PHP SDK, I see that the error you mentioned is thrown when MerchantPreferences is not given a valid NotifyUrl. I see you're setting the CancelUrl and ReturnUrl, but not the NotifyUrl. You may simply need to set that as well, i.e.:
$NotifyUrl = (some url goes here)
$obj->setNotifyUrl($NotifyUrl);
Reason behind it!
error comes from.
vendor\paypal\rest-api-sdk-php\lib\PayPal\Validation\UrlValidator.php
line.
if (filter_var($url, FILTER_VALIDATE_URL) === false) {
throw new \InvalidArgumentException("$urlName is not a fully qualified URL");
}
FILTER_VALIDATE_URL: according to this php function.
INVALID URL: "http://cat_n.domain.net.in/"; // IT CONTAIN _ UNDERSCORE.
VALID URL: "http://cat-n.domain.net.in/"; it separated with - dash
here you can dump your url.
vendor\paypal\rest-api-sdk-php\lib\PayPal\Validation\UrlValidator.php
public static function validate($url, $urlName = null)
{
var_dump($url);
}
And then check this here: https://www.w3schools.com/PHP/phptryit.asp?filename=tryphp_func_validate_url
you can check here what character will reason for invalid.

softlayer api : How to upgrade a block storage volume size

i tried to upgrade block(performance) storage volume and IOPs via API.
test code returns the error message :
"Error: com.softlayer.api.ApiException$Internal: Invalid price Block Storage (189443) provided on the order container.(code: SoftLayer_Exception_Order_Item_Invalid, status: 500)"
I am using placeOrder and verifyOrder method for order.
where can i find sample code to upgrade storage volume?
public void test03() throws Exception {
System.out.println("\nStorage Upgrade Test Start !!\n");
ApiClient client = new RestApiClient().withCredentials(username, apiKey);
com.softlayer.api.service.container.product.order.network.storage.asaservice.Upgrade storage = new com.softlayer.api.service.container.product.order.network.storage.asaservice.Upgrade();
Storage.Service service = Storage.service(client, 38366457L);
service.withMask().accountId();
service.withMask().id();
service.withMask().bytesUsed();
service.withMask().osTypeId();
service.withMask().iops();
service.withMask().username();
service.withMask().allowedIpAddresses();
service.withMask().replicationStatus();
service.withMask().parentVolume();
service.withMask().parentVolume().volumeStatus();
service.withMask().serviceResourceBackendIpAddress();
service.withMask().serviceResource().datacenter();
service.withMask().allowedHardware().allowedHost().credential().username().password();
service.withMask().allowedSubnets();
service.withMask().allowedVirtualGuests().allowedHost().credential().username().password();
service.withMask().allowedIpAddresses().allowedHost().credential().username().password();
service.withMask().snapshotCapacityGb();
service.withMask().snapshotSizeBytes();
service.withMask().snapshotSpaceAvailable();
service.withMask().parentVolume().snapshotSizeBytes();
service.withMask().parentVolume().snapshotSpaceAvailable();
service.withMask().properties().type();
service.withMask().billingItem();
service.withMask().billingItem().children().activeFlag();
service.withMask().billingItem().children().item();
service.withMask().properties().volume();
service.withMask().capacityGb();
service.withMask().nasType();
Storage storage1 = service.getObject();
Order order = null;
try {
// 1. Storage volume
storage.setVolumeSize(80L);
storage.setIops(400L);
storage1.setUpgradableFlag(true);
storage.setVolume(storage1);
order = storage;
// Set SoftLayer Package Id
order.setPackageId(759L);
order.setUseHourlyPricing(true);
// Set Data Center Location
order.setLocation("1854895");
List<Price> S_prices = new ArrayList<Price>();
//International Services
Price price1 = new Price();
price1.setId(189433L);
// 2. Block/File Storage
Price price2 = new Price();
price2.setId(189443L); //Block Storage
//Storage Space
Price price3 = new Price();
price3.setId(189753L);
//IOPS
Price price4 = new Price();
price4.setId(189813L);
S_prices.add(price1);
S_prices.add(price2);
S_prices.add(price3);
S_prices.add(price4);
// Set Item Prices
order.getPrices().addAll(S_prices);
Order baseContainer = new Order();
baseContainer.getOrderContainers().add(order);
// verify
Order verifiedOrder = com.softlayer.api.service.product.Order.service(client).verifyOrder(baseContainer);
// placeorder
com.softlayer.api.service.container.product.order.Receipt receipt = com.softlayer.api.service.product.Order.service(client).placeOrder(baseContainer, false);
} catch (Exception e) {
System.out.println("Error: " + e);
} finally {
System.out.println("\nTest End !!\n");
}
}
try deleting this price:
// 2. Block/File Storage
Price price2 = new Price();
price2.setId(189443L); //Block Storage
As you are upgrading a "storage_as_a_service" you only need that price (189433) and the prices for the volume size and IOPS
This is the RESTFul request that I used:
POST https://$USERNAME:$APIKEY#api.softlayer.com/rest/v3/SoftLayer_Product_Order/placeOrder
{
"parameters": [{
"complexType": "SoftLayer_Container_Product_Order_Network_Storage_AsAService_Upgrade",
"packageId": 759,
"volume": {
"id": 38740447
},
"volumeSize": 2000,
"iops": 1000,
"useHourlyPricing": true,
"prices": [{
"id": 190233
}, {
"id": 190293
}, {
"id": 189433
}],
"quantity": 1
}]
}
So I recommend you:
1.- Try upgrading your block storage using the control portal, it may an issue with your account or your block storage.
2.- Try the upgrading using the RESTFul request, maybe the java client is sending wrong the request.
3.- Try Looging your Java code and see if the RESTFul request that your Java code is sending is similar to the RESTFUL request that I posted for that you need to this:
Logging Logging the requests and response to stdout can be enabled by
invoking withLoggingEnabled on the RestApiClient. In order to log
elsewhere, simply make your own implementation of RestApiClient with
logRequest and logResponse overridden.
e.g.
ApiClient client = new RestApiClient().withCredentials(username, apiKey).withLoggingEnabled();
Regards
I solved a problem.
my code had two issue.
first, in case of upgrading a storage(Block/File), the Type isn't need
// 2. Block/File Storage
Price price2 = new Price();
price2.setId(189443L); //Block Storage
two, Wrapping Order of the upgrade's container isn't need
because to upgrade storage, the ComplexType must be "SoftLayer_Container_Product_Order_Network_Storage_AsAService_Upgrade"
but Order's ComplexType is "SoftLayer_Container_Product_Order"
Order baseContainer = new Order(); <-- ComplextType : SoftLayer_Container_Product_Order
baseContainer.getOrderContainers().add(order);
so i deleted them and I modifed the verifyOrder and placeOrder parameters to order variable.
Order verifiedOrder = com.softlayer.api.service.product.Order.service(client).verifyOrder(order);
// placeorder
com.softlayer.api.service.container.product.order.Receipt receipt = com.softlayer.api.service.product.Order.service(client).placeOrder(order, false);
this is a final code
public void test03() throws Exception {
System.out.println("\nStorage Upgrade Test Start !!\n");
ApiClient client = new RestApiClient().withCredentials(username, apiKey);
com.softlayer.api.service.container.product.order.network.storage.asaservice.Upgrade storage = new com.softlayer.api.service.container.product.order.network.storage.asaservice.Upgrade();
Storage.Service service = Storage.service(client, 38366457L);
service.withMask().id();
Storage storage1 = service.getObject();
Order order = null;
try {
// 1. Storage volume
storage.setVolumeSize(80L);
storage.setIops(400L);
storage1.setUpgradableFlag(true);
storage.setVolume(storage1);
order = storage;
// Set SoftLayer Package Id
order.setPackageId(759L);
order.setUseHourlyPricing(true);
// Set Data Center Location
order.setLocation("1854895");
List<Price> S_prices = new ArrayList<Price>();
//International Services
Price price1 = new Price();
price1.setId(189433L);
//Storage Space
Price price3 = new Price();
price3.setId(189753L);
//IOPS
Price price4 = new Price();
price4.setId(189813L);
S_prices.add(price1);
S_prices.add(price3);
S_prices.add(price4);
// Set Item Prices
order.getPrices().addAll(S_prices);
// verify
Order verifiedOrder = com.softlayer.api.service.product.Order.service(client).verifyOrder(order);
// placeorder
com.softlayer.api.service.container.product.order.Receipt receipt = com.softlayer.api.service.product.Order.service(client).placeOrder(order, false);
} catch (Exception e) {
System.out.println("Error: " + e);
} finally {
System.out.println("\nTest End !!\n");
}
}

Pass through Magento Purchase Order number to Shipworks ; then add to Fedex Reference field

I use Shipworks 3 with Magento 1.5.1 and would like to pass the Purchase order NUMBER through. Right now the Payment Type comes through but I need the PO number so it can go on/print on the Packaking slip, invoice, AND Shipping label.
Here's a snippet from the shipworks.php. I'm guessing I just have to add to this section but not sure what to add.
Thank you for any help.
$payment = $order->getPayment();
// CC info
if ($secure)
{
$cc_num = $payment->getCcNumber();
}
else
{
$cc_num = $payment->getCcLast4();
if (!empty($cc_num))
{
$cc_num = '************'.$payment->getCcLast4();
}
}
$cc_year = sprintf('%02u%s', $payment->getCcExpMonth(), substr($payment->getCcExpYear(), 2));
writeStartTag("Payment");
writeElement("Method", Mage::helper('payment')->getMethodInstance($payment->getMethod())->getTitle());
writeStartTag("CreditCard");
writeElement("Type", $payment->getCcType());
writeElement("Owner", $payment->getCcOwner());
writeElement("Number", $cc_num);
writeElement("Expires", $cc_year);
writeCloseTag("CreditCard");
writeCloseTag("Payment");
I was able to use the following to get my po number to show up in the notes. This is what I used. hope it helps.
// CC info
if ($secure)
{
$cc_num = $payment->getCcNumber();
}
else
{
$cc_num = $payment->getCcLast4();
if (!empty($cc_num))
{
$cc_num = '************'.$payment->getCcLast4();
}
}
$cc_year = sprintf('%02u%s', $payment->getCcExpMonth(), substr($payment->getCcExpYear(), 2));
writeStartTag("Payment");
writeElement("Method", Mage::helper('payment')->getMethodInstance($payment->getMethod())->getTitle());
writeStartTag("CreditCard");
writeElement("Type", $payment->getCcType());
writeElement("Owner", $payment->getCcOwner());
writeElement("Number", $cc_num);
writeElement("Expires", $cc_year);
writeCloseTag("CreditCard");
writeCloseTag("Payment");
writeStartTag("Notes");
writeFullElement("Note", $payment->getPoNumber(),array("public" =>"true"));
writeCloseTag("Notes");
WriteOrderItems($order->getAllItems());
WriteOrderTotals($order);
Shipworks is very picky about the XML tags that it receives. You can't just add something to the response because it'll throw errors in the SW software when it tries to sync with your Magento store. You can add it by using an existing element that isn't currently being used. In our case, we weren't using Gift Messages, which get added to the response as Notes, so I re-purposed the Notes element to contain something else.
Look at the WriteOrder function (around line 396) and find this section:
if ($order->getGiftMessageId())
{
$message = Mage::helper('giftmessage/message')->getGiftMessage($order->getGiftMessageId());
$messageString = "Gift message for ". $message['recipient']. ": ". $message['message'];
writeStartTag("Notes");
writeFullElement("Note", $messageString, array("public" => "true"));
writeCloseTag("Notes");
}
Comment out this section and add something like this:
if ($order->getPoNumber())
{
writeStartTag("Notes");
writeFullElement("Note", $order->getPoNumber(), array("public" => "true"));
writeCloseTag("Notes");
}
NOTE: I don't know if $order->getPoNumber() actually works...this is just a sample of what you'll need to do