Skip to content

A nifty utility pack for SAP OCI Punch-outs for dotnet

License

Notifications You must be signed in to change notification settings

LJFloor/PunchoutUtils

Repository files navigation

PunchoutUtils

A nifty utility pack for SAP OCI Punch-outs for dotnet

Features

For now there is only one feature

  • Serialize and deserialize a punch-out

Constants

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

Serialize / Deserialize

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

Bugs

Please create an issue on the github repo if you find anything that doesn't seem right.

About

A nifty utility pack for SAP OCI Punch-outs for dotnet

Resources

License

Stars

Watchers

Forks

Languages