贝宝与发票和订单确认在安卓应用程序



我必须开发一个购物车应用程序和集成Paypal。如何设置Paypal付款发票数据?

如何将产品名称,数量,价格添加到Paypal付款发票中.

这是我添加到购物车页面的产品代码:

public class SingleMenuItem extends Activity {
static final String KEY_TITLE = "Name";
static final String KEY_COST = "Price";
static final String KEY_TOTAL = "total";
static final String KEY_QTY = "qty";
static final String KEY_THUMB_URL = "Image";
private EditText edit_qty_code;
private TextView txt_total;
private TextView text_cost_code;
private double itemamount = 0;
private double itemquantity = 0;
String mTitle, mQty, mCost, mTotal;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.single);
Intent in = getIntent();
    String title = in.getStringExtra(KEY_TITLE);
    String thumb_url = in.getStringExtra(KEY_THUMB_URL);
    String cost = in.getStringExtra(KEY_COST);
    String total = in.getStringExtra(KEY_TOTAL);
    ImageLoader imageLoader = new ImageLoader(getApplicationContext());
    ImageView imgv = (ImageView) findViewById(R.id.single_thumb);
    final TextView txttitle = (TextView) findViewById(R.id.single_title);
    TextView txtheader = (TextView) findViewById(R.id.actionbar);
    text_cost_code = (TextView) findViewById(R.id.single_cost);
    edit_qty_code = (EditText) findViewById(R.id.single_qty);
    edit_qty_code.setText("1");
    txt_total = (TextView) findViewById(R.id.single_total);
    txttitle.setText(title);
    txtheader.setText(title);
    text_cost_code.setText(cost);
    txt_total.setText(total);
    imageLoader.DisplayImage(thumb_url, imgv);
    itemamount = Double.parseDouble(text_cost_code.getText().toString());
    txt_total.setText(Double.toString(itemamount));
    edit_qty_code.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            // TODO Auto-generated method stub
            if (!edit_qty_code.getText().toString().equals("")
                    || !edit_qty_code.getText().toString().equals("")) {
                itemquantity = Double.parseDouble(edit_qty_code.getText()
                        .toString());
                itemamount = Double.parseDouble(text_cost_code.getText()
                        .toString());
                txt_total.setText(Double
                        .toString(itemquantity * itemamount));
            } else {
                txt_total.setText("0.00");
            }
        }
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub
        }
        public void afterTextChanged(Editable s) {
        }
    });
    ImageButton mImgAddCart = (ImageButton) findViewById(R.id.img_add);
    mImgAddCart.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // TODO Auto-generated method stub
            mTitle = txttitle.getText().toString();
            mCost = text_cost_code.getText().toString();
            mCost = mCost.replace("From ", "");
            mTotal = txt_total.getText().toString();
            mTotal = mTotal.replace("From ", "");
            mQty = edit_qty_code.getText().toString();
            if (Constants.mItem_Detail.size() <= 0) {
                HashMap<String, String> mTempObj = new HashMap<String, String>();
                mTempObj.put(KEY_TITLE, mTitle);
                mTempObj.put(KEY_QTY, mQty);
                mTempObj.put(KEY_COST, mCost);
                mTempObj.put(KEY_TOTAL, mTotal);
                Constants.mItem_Detail.add(mTempObj);
            } else {
                for (int i = 0; i < Constants.mItem_Detail.size(); i++) {
                    if (Constants.mItem_Detail.get(i).get(KEY_TITLE)
                            .equals(mTitle)) {
                        Constants.mItem_Detail.remove(i);

                        break;
                    } else {
                    }
                }
                HashMap<String, String> mTempObj = new HashMap<String, String>();
                mTempObj.put(KEY_TITLE, mTitle);
                mTempObj.put(KEY_QTY, mQty);
                mTempObj.put(KEY_COST, mCost);
                mTempObj.put(KEY_TOTAL, mTotal);
                Constants.mItem_Detail.add(mTempObj);
            }
            AlertDialog.Builder alertdialog = new AlertDialog.Builder(
                    SingleMenuItem.this);
            alertdialog.setTitle(getResources()
                    .getString(R.string.app_name));
            alertdialog.setMessage("Add in ViewCart");
            alertdialog.setPositiveButton("OK",
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog,
                                int which) {
                            // TODO Auto-generated method stub
                            //finish();
                            return;
                        }
                    });
            alertdialog.show();
        }
    });
    ImageButton mImgViewCart = (ImageButton) findViewById(R.id.img_view);
    mImgViewCart.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent mInViewCart = new Intent(SingleMenuItem.this,
                    ViewCartActivity.class);
            startActivity(mInViewCart);
        }
    });

这是产品添加到购物车的代码:

ListView mLstView1 = (ListView) findViewById(R.id.listView1);
    TextView mTxtViewGrandTotal = (TextView) findViewById(R.id.mTxtViewGrandTotalValue);
    Button mBtnSubmit = (Button) findViewById(R.id.mBtnSubmit);
    ViewCartAdapter mViewCartAdpt = new ViewCartAdapter(
            ViewCartActivity.this);
    mLstView1.setAdapter(mViewCartAdpt);
    if (Constants.mItem_Detail.size() > 0) {
        Double mGTotal = Double.parseDouble(Constants.mItem_Detail.get(0)
                .get(SingleMenuItem.KEY_TOTAL));
        for (int i = 1; i < Constants.mItem_Detail.size(); i++) {
            mGTotal = mGTotal
                    + Double.parseDouble(Constants.mItem_Detail.get(i).get(
                            SingleMenuItem.KEY_TOTAL));
        }
        mGrandTotal = String.valueOf(mGTotal);
        mTxtViewGrandTotal.setText("$" + mGrandTotal);
    }
    mBtnSubmit.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
             Intent i = new Intent(getApplicationContext(), CustomerLogin.class);
                startActivity(i);
        }
    });

我的paypalintegrationactivity:

public class PayPalIntegrationActivity extends Activity implements OnClickListener {
private PayPal mPayPal;
private CheckoutButton launchPayPalButton;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pay_pal_integration);
    mPayPal=PayPal.initWithAppID(this,Constants.PAYPAL_APP_ID,PayPal.ENV_SANDBOX);
    initUI();
}

private void initUI() {
    launchPayPalButton = mPayPal.getCheckoutButton(this, 
            PayPal.BUTTON_278x43, CheckoutButton.TEXT_PAY);
    RelativeLayout.LayoutParams params = new
            RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
                    LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    params.bottomMargin = 10;
    launchPayPalButton.setLayoutParams(params);
    launchPayPalButton.setOnClickListener(this);
    ((RelativeLayout)findViewById(R.id.main_layout)).addView(launchPayPalButton);
}

@Override
public void onClick(View v) {
    payWithPaypal();
}

private PayPalPayment payWithPaypal() {
    PayPalPayment newPayment = new PayPalPayment();
    BigDecimal bigDecimal=new BigDecimal(10);
    newPayment.setSubtotal(bigDecimal);
    newPayment.setCurrencyType(Currency.getInstance(Locale.US));
    newPayment.setRecipient("krishnaveni.veeman@mercuryminds.com");
    newPayment.setMerchantName("My Merchant");
    newPayment.setSubtotal(new BigDecimal(mTotal));
    newPayment.setPaymentType(PayPal.PAYMENT_TYPE_GOODS);
    Intent paypalIntent = PayPal.getInstance().checkout(newPayment, this);
    this.startActivityForResult(paypalIntent, 1);
    PayPalInvoiceData invoice = new PayPalInvoiceData();
        return newPayment;

}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch(resultCode) {
    case Activity.RESULT_OK:
        String payKey = 
        data.getStringExtra(PayPalActivity.EXTRA_PAY_KEY);
        Toast.makeText(this,"Payment Successful",Toast.LENGTH_LONG).show();
        break;
    case Activity.RESULT_CANCELED:
        Toast.makeText(this,"Payment Cancel",Toast.LENGTH_LONG).show();
        break;
    case PayPalActivity.RESULT_FAILURE:
        Toast.makeText(this,"Payment Failed",Toast.LENGTH_LONG).show();
        String errorID = 
        data.getStringExtra(PayPalActivity.EXTRA_ERROR_ID);
        String errorMessage = 
                data.getStringExtra(PayPalActivity.EXTRA_ERROR_MESSAGE);
        break;
    }

这里我如何添加产品名称到paypalpayment发票。

您可以添加paypalinvoice对象到您的项目,然后您可以添加详细信息到该发票,

try this code
PayPalInvoiceItem item1 = new PayPalInvoiceItem();
item1.setName("Pink Stuffed Bunny");
item1.setTotalPrice(new BigDecimal("6.00"));
item1.setQuantity(3);
invoice.getInvoiceItems().add(item1);

相关内容

  • 没有找到相关文章

最新更新