Hi.,
I have to develop one Android shopping cart application with Paypal payment integration.
Here I have to pass the product title, qty ,price to Paypal.
Here I have to run the Android application and add the 2 product means the last added product detail only pass to Paypal.
How can I pass all the added product detail is send to Paypal.
This is my code:
[HIGH]
private PayPalPayment payWithPaypal() {
PayPalPayment newPayment = new PayPalPayment();
BigDecimal sPrice = new BigDecimal(total);
newPayment.setSubtotal(sPrice);
newPayment.setCurrencyType("USD");
newPayment.setRecipient("mercy._1357640918_biz@gmail.com");
newPayment.setMerchantName("My Merchant");
newPayment.setPaymentType(PayPal.PAYMENT_TYPE_GOODS);
PayPalInvoiceData invoice = new PayPalInvoiceData();
invoice.setTax(new BigDecimal("1.25"));
invoice.setShipping(new BigDecimal("4.50"));
PayPalInvoiceItem item1 = new PayPalInvoiceItem();
StringBuffer sb = new StringBuffer();
sb.append("<html><body><table>");
for (int i = 0; i < Constants.mItem_Detail.size(); i++) {
String title = Constants.mItem_Detail.get(i).get(SingleMenuItem.KEY_PNAME);
String qty = Constants.mItem_Detail.get(i).get(SingleMenuItem.KEY_QTY);
String cost = Constants.mItem_Detail.get(i).get(SingleMenuItem.KEY_PRICE);
String total = Constants.mItem_Detail.get(i).get(SingleMenuItem.KEY_TOTAL);
total_count=total_count+Integer.parseInt(qty);
item1.setName(title);
item1.setQuantity(total_count);
item1.setUnitPrice(new BigDecimal(cost));
item1.setTotalPrice(new BigDecimal(total));
}
sb.delete(0, sb.length());
invoice.getInvoiceItems().add(item1);
newPayment.setInvoiceData(invoice);
newPayment.setDescription("Quite a simple payment");
newPayment.setCustomID("8873482296");
newPayment.setIpnUrl("http://www.exampleapp.com/ipn");
newPayment.setMemo("Hi! I'm making a memo for a simple payment.");
Intent paypalIntent = PayPal.getInstance().checkout(newPayment, this);
this.startActivityForResult(paypalIntent, 1);
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();
Intent intent = new Intent(PayPalIntegrationActivity.this,InvoiceOrder.class);
intent.putExtra("GrandTotal", total);
intent.putExtra("Title",status);
startActivity(intent);
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;
}
}
public interface PayPalResultDelegate{
void onPaymentSucceeded(String payKey, String paymentStatus);
void onPaymentFailed(String paymentStatus, String correlationID,
String payKey, String errorID, String errorMessage);
void onPaymentCanceled(String paymentStatus);
}
}
[/HIGH]
I have to develop one Android shopping cart application with Paypal payment integration.
Here I have to pass the product title, qty ,price to Paypal.
Here I have to run the Android application and add the 2 product means the last added product detail only pass to Paypal.
How can I pass all the added product detail is send to Paypal.
This is my code:
[HIGH]
private PayPalPayment payWithPaypal() {
PayPalPayment newPayment = new PayPalPayment();
BigDecimal sPrice = new BigDecimal(total);
newPayment.setSubtotal(sPrice);
newPayment.setCurrencyType("USD");
newPayment.setRecipient("mercy._1357640918_biz@gmail.com");
newPayment.setMerchantName("My Merchant");
newPayment.setPaymentType(PayPal.PAYMENT_TYPE_GOODS);
PayPalInvoiceData invoice = new PayPalInvoiceData();
invoice.setTax(new BigDecimal("1.25"));
invoice.setShipping(new BigDecimal("4.50"));
PayPalInvoiceItem item1 = new PayPalInvoiceItem();
StringBuffer sb = new StringBuffer();
sb.append("<html><body><table>");
for (int i = 0; i < Constants.mItem_Detail.size(); i++) {
String title = Constants.mItem_Detail.get(i).get(SingleMenuItem.KEY_PNAME);
String qty = Constants.mItem_Detail.get(i).get(SingleMenuItem.KEY_QTY);
String cost = Constants.mItem_Detail.get(i).get(SingleMenuItem.KEY_PRICE);
String total = Constants.mItem_Detail.get(i).get(SingleMenuItem.KEY_TOTAL);
total_count=total_count+Integer.parseInt(qty);
item1.setName(title);
item1.setQuantity(total_count);
item1.setUnitPrice(new BigDecimal(cost));
item1.setTotalPrice(new BigDecimal(total));
}
sb.delete(0, sb.length());
invoice.getInvoiceItems().add(item1);
newPayment.setInvoiceData(invoice);
newPayment.setDescription("Quite a simple payment");
newPayment.setCustomID("8873482296");
newPayment.setIpnUrl("http://www.exampleapp.com/ipn");
newPayment.setMemo("Hi! I'm making a memo for a simple payment.");
Intent paypalIntent = PayPal.getInstance().checkout(newPayment, this);
this.startActivityForResult(paypalIntent, 1);
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();
Intent intent = new Intent(PayPalIntegrationActivity.this,InvoiceOrder.class);
intent.putExtra("GrandTotal", total);
intent.putExtra("Title",status);
startActivity(intent);
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;
}
}
public interface PayPalResultDelegate{
void onPaymentSucceeded(String payKey, String paymentStatus);
void onPaymentFailed(String paymentStatus, String correlationID,
String payKey, String errorID, String errorMessage);
void onPaymentCanceled(String paymentStatus);
}
}
[/HIGH]