Question

I was hired by a group to develop a mobile application that ran on the three major mobile os platforms. I chose to use codenameone as it makes cross platform development easy. However, the group have recently changed their design plan to include in-app billing.

I would like to know the process for doing in-app billing using codenameone. Is there a go-to tutorial? My preliminary research shows there is a com.codename1.payment library which can be used but the method of implementation is not clear.

Any help will be much appreciated.

NB: Please note that I am already registered with Android, BlackBerry and Apple as an app vendor. All I require is a tutorial/guide on how to integrate my app with the stores using codenameone.

Thanks

Was it helpful?

Solution

In app billing works for Android and iOS with Codename One but isn't supported on other platforms so it won't work for Blackberry. This is the code from the kitchen sink demo for in-app-purchase:

    final Container purchaseDemo = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    final Purchase p = Purchase.getInAppPurchase();

    if(p != null) {
        if(p.isManualPaymentSupported()) {
            purchaseDemo.addComponent(new Label("Manual Payment Mode"));
            final TextField tf = new TextField("100");
            tf.setHint("Send us money, thanks");
            Button sendMoney = new Button("Send Us Money");
            sendMoney.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    p.pay(Double.parseDouble(tf.getText()), "USD");
                }
            });
            purchaseDemo.addComponent(tf);
            purchaseDemo.addComponent(sendMoney);
        } 
        if(p.isManagedPaymentSupported()) {
            purchaseDemo.addComponent(new Label("Managed Payment Mode"));
            for(int iter = 0 ; iter < ITEM_NAMES.length ; iter++) {
                Button buy = new Button(ITEM_NAMES[iter]);
                final String id = ITEM_IDS[iter];
                buy.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        p.purchase(id);
                    }
                });
                purchaseDemo.addComponent(buy);
            }
        } 
    } else {
        purchaseDemo.addComponent(new Label("Payment unsupported on this device"));
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top