A nifty utility pack for SAP OCI Punch-outs for dotnet
For now there is only one feature
- Serialize and deserialize a punch-out
In this document, we will use the following string as a punch-out:
NEW_ITEM-DESCRIPTION%5B0%5D%3DRubber%20duck&NEW_ITEM-QUANTITY%5B0%5D%3D1&NEW_ITEM-DESCRIPTION%5B1%5D%3DData%20structures%20in%20PHP%20%28book%29&NEW_ITEM-QUANTITY%5B1%5D%3D1
Below is a neatly formatted version so you can read it:
NEW_ITEM-DESCRIPTION[0]=Rubber duck&
NEW_ITEM-QUANTITY[0]=1&
NEW_ITEM-DESCRIPTION[1]=Data structures in PHP (book)&
NEW_ITEM-QUANTITY[1]=1
Of course, there are many more fields as documented: https://punchoutcommerce.com/docs/sap-oci-5.pdf
// Deserialize
var entries = PunchoutSerializer.Deserialize("NEW_ITEM-DESCRIPTION%5B0%5D%3DRubber%20duck&NEW_ITEM-QUANTITY%5B0%5D%3D1&NEW_ITEM-DESCRIPTION%5B1%5D%3DData%20structures%20in%20PHP%20%28book%29&NEW_ITEM-QUANTITY%5B1%5D%3D1");
// Serialize back to punch-out
var text = PunchoutSerializer.Serialize(entries);
// Or a single item
text = PunchoutSerialize.Serialize(entries.First());
You can also deserialize to your custom model you use for your webshop or your ERP system. Your model should implement the IPunchoutEntry
interface.
It is also possible to inherit the PunchoutEntry
model, since this class implements IPunchoutEntry
as well. Make sure you map the correct fields to your model:
using PunchoutUtils.Attributes;
public class MyCustomModel : IPunchoutEntry
{
[FieldName("DESCRIPTION[n]")]
public string Description { get; set; }
[FieldName("QUANTITY[n]")]
public int Quantity { get; set; }
}
A list of valid field names can be found here: https://punchoutcommerce.com/docs/sap-oci-5.pdf.
The n
will be replaced by the index of the item.
var entries = PunchoutSerializer.Deserialize<MyCustomModel>("NEW_ITEM-DESCRIPTION%5B0%5D%3DRubber%20duck&NEW_ITEM-QUANTITY%5B0%5D%3D1&NEW_ITEM-DESCRIPTION%5B1%5D%3DData%20structures%20in%20PHP%20%28book%29&NEW_ITEM-QUANTITY%5B1%5D%3D1");
Please create an issue on the github repo if you find anything that doesn't seem right.