View source | Discuss this page | Page history | Printable version   

Retail:Developers Guide/How-to/How to add an action in the payment toolbar

Contents

Introduction

In the payment toolbar appear usually only the payment types configured in the POS Terminal window. This toolbar can be extended with new buttons and actions that add new elements to the payments table that are not technically payments like on-credit sales, gift cards, bonuses, etc...

These new kind of payment elements must be managed properly in the server side to do the right actions instead of saving a real payment and also must be managed properly in the client side when loading receipts from the server.

This document explains how to implement all these actions.

Implementation

Create a new button

This section explains how to create a new button in the payments toolbar:

Payments toolbar.png

This button has been created with the following javascript code:

 
OB.OBPOSPointOfSale.UI.ToolbarPayment.prototype.sideButtons.push({
command: 'PaymentProcessorEmpty',
label: 'Test',
permission: 'org.openbravo.retail.posterminal.PaymentProcessorEmpty',
stateless: false,
action: function (keyboard, txt) {
  var amount = OB.DEC.number(OB.I18N.parseNumber(txt || ''));
  amount = _.isNaN(amount) ? keyboard.receipt.getPending() : amount;
  keyboard.receipt.addPayment(new OB.Model.PaymentLine({
      'kind': 'org.openbravo.retail.posterminal.PaymentProcessorEmpty',
      'name': 'Test',
      'description': 'Description',
      'amount': amount
    }));
  } 
});

Basically this registers a new button definition to the object OB.OBPOSPointOfSale.UI.ToolbarPayment.prototype.sideButtons. This button definition has the following properties.

In this case the payment added by the action has the following properties:

Create the payment processor

For payments that are not technically payments, you must create a server side java class that processes this payment.

In the payment object the kind property defines the java class name to use. This java class must implement the interface PaymentProcessor. This is an example of a java class that does not do anything. This is the right action for on-credit payment definitions:

 
 ************************************************************************************
 * Copyright (C) 2012 Openbravo S.L.U.
 * Licensed under the Openbravo Commercial License version 1.0
 * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
 * or in the legal folder of this module distribution.
 ************************************************************************************
 */
 
package org.openbravo.retail.posterminal;
 
import java.math.BigDecimal;
 
import org.codehaus.jettison.json.JSONObject;
import org.openbravo.model.common.invoice.Invoice;
import org.openbravo.model.common.order.Order;
 
public class PaymentProcessorEmpty implements PaymentProcessor {
 
  public void process(JSONObject payment, Order order, Invoice invoice, BigDecimal writeoff) {
    // Do nothing
  }
}

Create the paid orders loader

When a paid order is loaded in the POS the model returned by the server side does not contain this kind of payments and must be generated according the information returned. This is done adding a processor that is executed when a paid order is loaded. this processor has the following structure:

 
function paymentProcessor(model) {
  // Adds the payments to the model.
}

And it is registered using the following javascript code:

 
OB.Model.modelLoaders.push(paymentProcessor);

Retrieved from "http://wiki.openbravo.com/wiki/Retail:Developers_Guide/How-to/How_to_add_an_action_in_the_payment_toolbar"

This page has been accessed 5,711 times. This page was last modified on 17 March 2014, at 17:41. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.