Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 41
Registered: ‎07-19-2011
My Device: 9500
My Carrier: airtel

Payment Api 1.5

Hi All,

 

I am using payment api 1.5 which was released recently by rim. But i am getting exeption like this unable to athunicate payment service. I am attaching the code please have a look once

/**
 * 
 */
package com.id.Test;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.MainScreen;
import net.rimlib.blackberry.api.paymentsdk.AppWorldUpdateRequired;
import net.rimlib.blackberry.api.paymentsdk.ExistingPurchasesResult;
import net.rimlib.blackberry.api.paymentsdk.PaymentEngine;
import net.rimlib.blackberry.api.paymentsdk.PaymentException;
import net.rimlib.blackberry.api.paymentsdk.Purchase;
import net.rimlib.blackberry.api.paymentsdk.PurchaseArgumentsBuilder;

/**
 * @author K.Sandeep Sagar
 * 
 */
public class PaymentScreen extends MainScreen {

	/**
	 * 
	 */
	public PaymentScreen() {
		ButtonField prevPurchaesField = new ButtonField("Get Purchases",
				ButtonField.CONSUME_CLICK);
		add(prevPurchaesField);
		prevPurchaesField.setChangeListener(new FieldChangeListener() {

			public void fieldChanged(Field field, int context) {

				// engine.setConnectionMode(PaymentEngine.CONNECTION_MODE_LOCAL);

				UiApplication.getUiApplication().invokeLater(new Runnable() {

					public void run() {
						final PaymentEngine engine = PaymentEngine
								.getInstance();
						if (engine != null) {
							try {

								// Purchase purchase = engine.purchase(arguments
								// .build());
								ExistingPurchasesResult purchase = engine
										.getExistingPurchases(true);
								Dialog.inform("Purchase of "
										+ purchase.isSuccessful()
										+ " is successful.");
							} catch (PaymentException e) {
								Dialog.inform(e.getMessage());
							}
						}

					}
				});

			}
		});
		ButtonField buyField1 = new ButtonField("Buy",
				ButtonField.CONSUME_CLICK);
		add(buyField1);
		buyField1.setChangeListener(new FieldChangeListener() {

			public void fieldChanged(Field field, int context) {

				UiApplication.getUiApplication().invokeLater(new Runnable() {

					public void run() {
						PaymentEngine engine = PaymentEngine.getInstance();
						try {
							PaymentEngine.isAppWorldInstalledAndAtCorrectVersion();
						} catch (AppWorldUpdateRequired e1) {
							PaymentEngine.upDateAppWorld();
							e1.printStackTrace();
						}
						
						PurchaseArgumentsBuilder arguments = new PurchaseArgumentsBuilder()
								.withDigitalGoodSku("abc123")
								.withDigitalGoodName(
										"Adventures of a BlackBerry Java Developer")
								.withPurchasingAppName("My eBooks")
								.withMetadata("ISBN 34560202010");
						try {
							engine.checkExisting("abc123");
						} catch (AppWorldUpdateRequired e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						} catch (PaymentException e1) {
							// TODO Auto-generated catch block
							Dialog.inform(e1.getMessage());
						}
						if (engine != null) {
							try {

								Purchase purchase = engine.purchase(arguments
										.build());
								// Purchase[] purchase = engine
								// .getExistingPurchases(true);
								Dialog.inform("Purchase of "
										+ purchase.getTransactionId()
										+ " is successful.");
							} catch (PaymentException e) {
								Dialog.inform(e.getMessage());
							}
						}

					}
				});

			}
		});
	}
}

  Please help me how to provide subscriptions for applictions.

Thank you......

Contributor
Posts: 41
Registered: ‎07-19-2011
My Device: 9500
My Carrier: airtel

Re: Payment Api 1.5

/**
 * 
 */
package com.id.Test;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.MainScreen;
import net.rimlib.blackberry.api.paymentsdk.AppWorldUpdateRequired;
import net.rimlib.blackberry.api.paymentsdk.ExistingPurchasesResult;
import net.rimlib.blackberry.api.paymentsdk.PaymentEngine;
import net.rimlib.blackberry.api.paymentsdk.PaymentException;
import net.rimlib.blackberry.api.paymentsdk.Purchase;
import net.rimlib.blackberry.api.paymentsdk.PurchaseArgumentsBuilder;

/**
 * @author K.Sandeep Sagar
 * 
 */
public class PaymentScreen extends MainScreen {

	/**
	 * 
	 */
	public PaymentScreen() {
		ButtonField prevPurchaesField = new ButtonField("Get Purchases",
				ButtonField.CONSUME_CLICK);
		add(prevPurchaesField);
		prevPurchaesField.setChangeListener(new FieldChangeListener() {

			public void fieldChanged(Field field, int context) {

				// engine.setConnectionMode(PaymentEngine.CONNECTION_MODE_LOCAL);

				UiApplication.getUiApplication().invokeLater(new Runnable() {

					public void run() {
						final PaymentEngine engine = PaymentEngine
								.getInstance();
						if (engine != null) {
							try {

								// Purchase purchase = engine.purchase(arguments
								// .build());
								ExistingPurchasesResult purchase = engine
										.getExistingPurchases(true);
								Dialog.inform("Purchase of "
										+ purchase.isSuccessful()
										+ " is successful.");
							} catch (PaymentException e) {
								Dialog.inform(e.getMessage());
							}
						}

					}
				});

			}
		});
		ButtonField buyField1 = new ButtonField("Buy",
				ButtonField.CONSUME_CLICK);
		add(buyField1);
		buyField1.setChangeListener(new FieldChangeListener() {

			public void fieldChanged(Field field, int context) {

				UiApplication.getUiApplication().invokeLater(new Runnable() {

					public void run() {
						PaymentEngine engine = PaymentEngine.getInstance();
						try {
							PaymentEngine
									.isAppWorldInstalledAndAtCorrectVersion();
						} catch (AppWorldUpdateRequired e1) {
							PaymentEngine.upDateAppWorld();
							e1.printStackTrace();
						}

						PurchaseArgumentsBuilder arguments = new PurchaseArgumentsBuilder()
								.withDigitalGoodSku("abc123")
								.withDigitalGoodName(
										"Adventures of a BlackBerry Java Developer")
								.withPurchasingAppName("My eBooks")
								.withMetadata("ISBN 34560202010");
						try {
							engine.checkExisting("abc123");
						} catch (AppWorldUpdateRequired e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						} catch (PaymentException e1) {
							// TODO Auto-generated catch block
							Dialog.inform(e1.getMessage());
						}
						if (engine != null) {
							try {

								Purchase purchase = engine.purchase(arguments
										.build());
								// Purchase[] purchase = engine
								// .getExistingPurchases(true);
								Dialog.inform("Purchase of "
										+ purchase.getTransactionId()
										+ " is successful.");
							} catch (PaymentException e) {
								Dialog.inform(e.getMessage());
							}
						}

					}
				});

			}
		});
	}
}

 

Contributor
Posts: 41
Registered: ‎07-19-2011
My Device: 9500
My Carrier: airtel

Re: Payment Api 1.5

/**
 *
 */
package com.id.Test;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.MainScreen;
import net.rimlib.blackberry.api.paymentsdk.AppWorldUpdateRequired;
import net.rimlib.blackberry.api.paymentsdk.ExistingPurchasesResult;
import net.rimlib.blackberry.api.paymentsdk.PaymentEngine;
import net.rimlib.blackberry.api.paymentsdk.PaymentException;
import net.rimlib.blackberry.api.paymentsdk.Purchase;
import net.rimlib.blackberry.api.paymentsdk.PurchaseArgumentsBuilder;

/**
 * @author K.Sandeep Sagar
 *
 */
public class PaymentScreen extends MainScreen {

    /**
     *
     */
    public PaymentScreen() {
        ButtonField prevPurchaesField = new ButtonField("Get Purchases",
                ButtonField.CONSUME_CLICK);
        add(prevPurchaesField);
        prevPurchaesField.setChangeListener(new FieldChangeListener() {

            public void fieldChanged(Field field, int context) {

                // engine.setConnectionMode(PaymentEngine.CONNECTION_MODE_LOCAL);

                UiApplication.getUiApplication().invokeLater(new Runnable() {

                    public void run() {
                        final PaymentEngine engine = PaymentEngine
                                .getInstance();
                        if (engine != null) {
                            try {

                                // Purchase purchase = engine.purchase(arguments
                                // .build());
                                ExistingPurchasesResult purchase = engine
                                        .getExistingPurchases(true);
                                Dialog.inform("Purchase of "
                                        + purchase.isSuccessful()
                                        + " is successful.");
                            } catch (PaymentException e) {
                                Dialog.inform(e.getMessage());
                            }
                        }

                    }
                });

            }
        });
        ButtonField buyField1 = new ButtonField("Buy",
                ButtonField.CONSUME_CLICK);
        add(buyField1);
        buyField1.setChangeListener(new FieldChangeListener() {

            public void fieldChanged(Field field, int context) {

                UiApplication.getUiApplication().invokeLater(new Runnable() {

                    public void run() {
                        PaymentEngine engine = PaymentEngine.getInstance();
                        try {
                            PaymentEngine
                                    .isAppWorldInstalledAndAtCorrectVersion();
                        } catch (AppWorldUpdateRequired e1) {
                            PaymentEngine.upDateAppWorld();
                            e1.printStackTrace();
                        }

                        PurchaseArgumentsBuilder arguments = new PurchaseArgumentsBuilder()
                                .withDigitalGoodSku("abc123")
                                .withDigitalGoodName(
                                        "Adventures of a BlackBerry Java Developer")
                                .withPurchasingAppName("My eBooks")
                                .withMetadata("ISBN 34560202010");
                        try {
                            engine.checkExisting("abc123");
                        } catch (AppWorldUpdateRequired e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        } catch (PaymentException e1) {
                            // TODO Auto-generated catch block
                            Dialog.inform(e1.getMessage());
                        }
                        if (engine != null) {
                            try {

                                Purchase purchase = engine.purchase(arguments
                                        .build());
                                // Purchase[] purchase = engine
                                // .getExistingPurchases(true);
                                Dialog.inform("Purchase of "
                                        + purchase.getTransactionId()
                                        + " is successful.");
                            } catch (PaymentException e) {
                                Dialog.inform(e.getMessage());
                            }
                        }

                    }
                });

            }
        });
    }
}