问题
I'm exploring whether it's possible for me to implement an idea I've had in iOS. However, the idea depends on being able to give users money. Is this possible in iOS? I know Apple wants you to use StoreKit when taking money from users (in-app purchases, etc), but is there even a mechanism in StoreKit to give money to users, and if not, do the iOS rules let one use a third-party service like PayPal to give users money?
回答1:
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");
}
来源:https://stackoverflow.com/questions/12132206/processing-payments-to-users-in-ios