0

以下のコードを使用して、アプリの購入に実装しています。プロジェクトに Blackberry paymentapi.jar を追加しました。そして、私は以下のリンクからこのコードを参照しました:

http://docs.blackberry.com/en/developers/deliverables/20374/Developing_your_application_1326736_11.jsp#Initiating_a_purchase_1314129_11

package mypackage;
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.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
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;

public class PurchaseDemo extends UiApplication
{
    public static void main(String[] args) 
    {
        PurchaseDemo app = new PurchaseDemo();
        app.enterEventDispatcher(); 
    }

    public PurchaseDemo() 
    {   
        pushScreen(new PurchaseDemoScreen());
    }

    private static class PurchaseDemoScreen extends MainScreen implements FieldChangeListener
    {
        private ButtonField buyButton;
        private ButtonField displayButton;
        private BasicEditField digitalGoodName;
        private BasicEditField digitalGoodSku;

        private PaymentEngine engine = PaymentEngine.getInstance();

        public PurchaseDemoScreen()
        {
            setTitle("Payment Service SDK Demo");

            if (engine != null)
            {
                engine.setConnectionMode(PaymentEngine.CONNECTION_MODE_LOCAL);

                digitalGoodName = new BasicEditField("Digital Good Name:  ", 
                    "Sample Good");
                add(digitalGoodName);

                digitalGoodSku = new BasicEditField("Digital Good SKU:   ", 
                    "abc123");
                add(digitalGoodSku);

                HorizontalFieldManager hfm = new HorizontalFieldManager();
                add(hfm);

                buyButton = new ButtonField("Buy");
                buyButton.setChangeListener(this);
                hfm.add(buyButton);

                displayButton = new ButtonField("Display Purchases");
                displayButton.setChangeListener(this);
                hfm.add(displayButton);
            }
            else
            {
                RichTextField errorMessage = new RichTextField("Sorry, in-app purchases are unavailable");
                add(errorMessage);
            }
        }

        public void fieldChanged(Field field, int context)
        {
            if (field == buyButton)
            {
                String name = digitalGoodName.getText();
                String sku = digitalGoodSku.getText();

                PurchaseArgumentsBuilder arguments = new PurchaseArgumentsBuilder()
                    .withDigitalGoodSku( sku )
                    .withDigitalGoodName( name )
                    .withMetadata( name )
                    .withPurchasingAppName( "Payment Service SDK Demo" );

                try 
                {
                    Purchase purchase = engine.purchase(arguments.build());
                    Dialog.inform("Purchase of " + purchase.getMetadata() 
                        + " is successful.");
                }
                catch (IllegalArgumentException e) 
                {
                    Dialog.inform(e.getMessage());
                }
                catch (PaymentException e) 
                {
                    Dialog.inform(e.getMessage());
                }
            }
            else if (field == displayButton)
            {
                try 
                {
                    Purchase[] purchases = engine.getExistingPurchases(true);

                    if (purchases.length != 0)
                    {
                        if (getFieldCount() > 3)
                        {
                            deleteRange(3, (getFieldCount()-3));
                        }

                        for (int i = 0; i < purchases.length; i++ )
                        {
                            RichTextField purchaseRecord = new RichTextField("Name: " 
                                + purchases[i].getMetadata() + "    SKU: " 
                                + purchases[i].getDigitalGoodSku());
                            add(purchaseRecord);
                        }
                    }
                    else
                    {
                       Dialog.inform("No existing purchases");
                    }       
                } 
                catch (PaymentException e) 
                {
                    Dialog.inform(e.getMessage());
                }
            }
        }                   
    }
}

上記のコードでは

engine.setConnectionMode(PaymentEngine.CONNECTION_MODE_LOCAL);
Purchase[] purchases = engine.getExistingPurchases(true);

エラーを赤で示しています。

4

1 に答える 1

0

PaymentEngine#setConnectionMode() はサポートされなくなりました: http://www.blackberry.com/developers/docs/payment/1.8api/

サンドボックス アカウントを使用して引き続きテストできます: http://docs.blackberry.com/en/developers/deliverables/40131/Live_testing_1935047_11.jsp

于 2012-10-18T12:06:26.797 に答える