Processing payments to users in iOS

安稳与你 提交于 2019-12-02 11:23:54

Yes, one can use a third party service like Paypal for payment. To implement Paypal mechanism go through the following steps.

1) Download Mobile Payment Libraries for iOS form here

2) import PayPal.h file in header file of your View Controller.

3) include following frameworks in project -- Security.framework, MapKit, ImageIO, SystemConfiguration

4) also include following two libraries file - libz.dylib, libxml2.dylib

5) Create a button for payment like

     UIButton checkOutBtn=[[PayPal getPayPalInst] getPayButtonWithTarget:self andAction:@selector(payWithPayPal) andButtonType:BUTTON_152x33 andButtonText:BUTTON_TEXT_PAY];
     checkOutBtn.frame=CGRectMake(60, 100, 200, 45);
     [self.view addSubview:checkOutBtn];  

6) implement button action method using following code:

    -(void) payWithPayPal
    {
           [PayPal getPayPalInst].shippingEnabled=TRUE;
           [PayPal getPayPalInst].dynamicAmountUpdateEnabled=TRUE;
           [PayPal getPayPalInst].feePayer=FEEPAYER_EACHRECEIVER;

           PayPalPayment *payment=[[[PayPalPayment alloc] init] autorelease];
           payment.recipient=@"xyz@paypal.com";
           payment.paymentCurrency=@"USD";

           payment.description = @"Paypal";
           payment.merchantName = @"Title Name";

           //subtotal of all items, without tax and shipping

           payment.subTotal = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%1.2f", 5320.50 ]];   // total Price

          //invoiceData is a PayPalInvoiceData object which contains tax, shipping, and a list of PayPalInvoiceItem objects

           payment.invoiceData = [[[PayPalInvoiceData alloc] init] autorelease];
           payment.invoiceData.totalShipping = [NSDecimalNumber decimalNumberWithString:@"2"];   // Shipping Cost
           payment.invoiceData.totalTax = [NSDecimalNumber decimalNumberWithString:@"0.35"];   // Tax On Product

           //invoiceItems is a list of PayPalInvoiceItem objects
           //NOTE: sum of totalPrice for all items must equal payment.subTotal

           payment.invoiceData.invoiceItems = [NSMutableArray array];
           PayPalInvoiceItem *item = [[[PayPalInvoiceItem alloc] init] autorelease];

           item.totalPrice = payment.subTotal;
           item.name = @"Product Name";
           [payment.invoiceData.invoiceItems addObject:item];

           [[PayPal getPayPalInst] checkoutWithPayment:payment];
    }

7) Use following delegates

    -(void)paymentSuccessWithKey:(NSString *)payKey andStatus:(PayPalPaymentStatus)paymentStatus
    {
           NSLog(@"Successfully Paid");
    }
    -(void)paymentCanceled
    {
           NSLog(@"Cancelled");
    }
    - (void)paymentFailedWithCorrelationID:(NSString *)correlationID
    {
           NSLog(@"Failed");
    }
    -(void)paymentLibraryExit
    {
           NSLog(@"Exit");
    }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!