Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paypal with a shopping cart button in iphone

I'm making an app in which I need to integrate PayPal. I integrated the PayPal button, but I don't know how to add a shopping cart button, so that I can total all the products.

like image 682
Asish AP Avatar asked Aug 19 '11 17:08

Asish AP


People also ask

How do I add a PayPal shopping cart button?

Create PayPal buttons: Go to PayPal Payment Button page, choose a button, follow the customization prompts, and click Create Button. Add a button to your website: On your site, access Code Editor or View or Edit HTML. Go to where you want the button and paste your code.


1 Answers

Here's how I did it for a sample app. I built a cart in my app (just a simple dictionary of items that I can add to and subtract from in the normal workflow) and at the top right of the app there's a button that says "Checkout". At which point the user will be presented with a view of their cart and using the Paypal MPL library I make a request to generate a "pay with paypal" button.

UIButton *button = [[PayPal getPayPalInst] getPayButtonWithTarget:self andAction:initiatePayment andButtonType:BUTTON_294x43];

Then in my Initiate Payment method I fill the cart.

(void)initiatePayment {
    [preapprovalField resignFirstResponder];

    [PayPal getPayPalInst].shippingEnabled = TRUE;
    [PayPal getPayPalInst].dynamicAmountUpdateEnabled = TRUE;
    [PayPal getPayPalInst].feePayer = FEEPAYER_EACHRECEIVER;

    PayPalPayment *payment = [[[PayPalPayment alloc] init] autorelease];
    payment.recipient = @"[email protected]";
    payment.paymentCurrency = @"USD";
    payment.description = @"Cart Checkout";
    payment.merchantName = @"Fake Store O Stuff";
    payment.subTotal = [NSDecimalNumber decimalNumberWithString:@"10"];
    payment.invoiceData = [[[PayPalInvoiceData alloc] init] autorelease];

    payment.invoiceData.invoiceItems = [NSMutableArray array];
    for(invoiceItem cartItem in Cart.Items) {
        PayPalInvoiceItem *item = [[[PayPalInvoiceItem alloc] init] autorelease];
        item.totalPrice = cartItem.totalPrice;
        item.name = cartItem.name;
        [payment.invoiceData.invoiceItems addObject:item];
    }
    payment.invoiceData.totalShipping = [NSDecimalNumber decimalNumberWithString:@"2"];
    payment.invoiceData.totalTax = [NSDecimalNumber decimalNumberWithString:@"0.35"];

    [[PayPal getPayPalInst] checkoutWithPayment:payment];
}
like image 181
Tony Ashworth Avatar answered Sep 28 '22 05:09

Tony Ashworth