// This is a sample PostalPoint plugin that adds a card payment processor.
exports.init=function(){
global.apis.pos.registerCardProcessor({
name:"Demo Card Processor",
init:asyncfunction(){
// This function runs once after starting PostalPoint
// and before any other card processor functions are called.
},
checkout:asyncfunction({amount,capture=true}){
// amount is an integer number of pennies.
// If an error is encountered during processing,
// display an error message in a dialog and return boolean false.
// If this function returns anything except false or undefined, and doesn't throw an error,
// it is assumed the payment was successful.
try{
if(capture){
// authorize, capture, add a ReceiptPayment to the receipt, and return boolean true.
global.apis.pos.addOnscreenPaymentLog("Getting card payment...");// Add a line to the onscreen card processing status log
awaitglobal.apis.util.delay(1000);// Replace this with something useful!
global.apis.pos.addReceiptPayment(
newglobal.apis.pos.ReceiptPayment(
(amount/100).toFixed(2)*1,
"card",// Payment type. Accepted values are card, ach, crypto, cash, check, account, and free. Other types will be displayed as-is to the user and on the receipt.
"Demo Card\nCardholder Name, etc\nMore info for receipt"// Additional text for receipt
// only authorize the payment, don't actually capture/charge the payment method,
// and return whatever transaction data that will be passed to finishPayment to capture the payment.
awaitglobal.apis.util.delay(1000);// Replace this with something useful!
return{amount:amount};
}
}catch(ex){
global.apis.pos.addOnscreenPaymentLog(`Error: ${ex.message} [okay to put extra details here for troubleshooting or tech support, it's visible to the cashier]`);
if(global.apis.kiosk.isKiosk()){
// This message will be shown to an end-user/customer, not a cashier/employee
global.apis.alert("Your card was declined.","Card Error");
}else{
global.apis.alert("The customer's card was declined.","Card Error");
}
returnfalse;
}
},
cancelCheckout:function(){
// The user requested to cancel the payment.
// Reset the terminal to its resting state, clear its screen, etc.
},
finishPayment:asyncfunction({checkoutResponse}){
// Finish a payment that was authorized but not captured because checkout was called with capture = false
// If payment was already captured and added to the receipt for some reason, just return true.
awaitglobal.apis.util.delay(1000);// Replace this with something useful!
global.apis.pos.addReceiptPayment(
newglobal.apis.pos.ReceiptPayment(
(checkoutResponse.amount/100).toFixed(2)*1,
"card",// Payment type.
"Demo Card\nCardholder Name, etc\nMore info for receipt"// Additional text for receipt
)
);
returntrue;
},
updateCartDisplay:function(receipt){
// Show transaction data on the card reader display.
// This function will be called when the cart or total changes.
console.log(receipt);
// Sample structure of the receipt variable:
receipt={
"items":[
{
"id":"testitem",
"label":"Test Item",
"text":"",
"priceEach":2,
"qty":1,
"cost":0,
"retail":2,
"taxRate":0.1,
"free":false,
"barcode":"",
"certifiedInfo":false,
"isMerch":true,
"surcharge":false
},
{
"id":"9100123456789012345678",
"label":"Test Package",
"text":"Package Details\nTracking # 9100 1234 5678 9012 3456 78\nTo:\nTEST PERSON\nORGANIZATION INC\n123 TEST ROAD\nTESTTOWN TE 99999-0001",
"priceEach":8,
"qty":1,
"cost":0,
"retail":8,
"taxRate":0,
"free":false,
"barcode":"9100123456789012345678",
"certifiedInfo":false,
"isMerch":false,
"surcharge":false,
"toAddress":{
"name":"TEST PERSON",
"company":"ORGANIZATION INC",
"street1":"123 TEST ROAD",
"street2":null,
"city":"TESTTOWN",
"state":"TE",
"zip":"99999-0001",
"email":null,
"phone":null,
"country":"US"
},
"fromAddress":{
"name":"TEST PERSON",
"company":"ORGANIZATION INC",
"street1":"123 TEST ROAD",
"street2":null,
"city":"TESTTOWN",
"state":"TE",
"zip":"99999-0001",
"email":null,
"phone":null,
"country":"US"
}
}
],
"payments":[
{
"amount":10,
"amountFormatted":"$10.00",
"type":"cash",
"label":"Cash",
"text":"",
"texthtml":"",
"id":"12345678_cash_10"
},
{
"amount":12.34,
"amountFormatted":"$12.34",
"type":"card",
"label":"Card",
"text":"Card Details here\n1234abcd",
"texthtml":"Card Details here<br />1234abcd",
"id":"87654321_card_12.34"
}
],
"subtotal":10,
"subtotalFormatted":"$10.00",
"tax":0.2,
"taxFormatted":"$0.20",
"grandTotal":10.2,
"grandTotalFormatted":"$10.20",
"paid":22.34,
"paidFormatted":"$22.34",
"due":-12.14,// If negative, is the amount of change owed to the customer instead