我正在探索是否有可能实现我在 iOS 中的想法。然而,这个想法取决于能够给用户钱。这在 iOS 中可行吗?我知道 Apple 希望您在从用户那里收钱(应用内购买等)时使用 StoreKit,但是 StoreKit 中是否有一种机制可以给钱给用户,如果不允许,iOS 规则是否允许使用 PayPal 等第三方服务向用户付款?
最佳答案
是的,可以使用 Paypal 等第三方服务进行付款。要实现 Paypal 机制,请执行以下步骤。
1) 下载适用于 iOS 的移动支付库表格 here
2) 在 View Controller 的头文件中导入 PayPal.h 文件。
3) 在项目中包含以下框架 -- Security.framework、MapKit、ImageIO、SystemConfiguration
4) 还包括以下两个库文件- libz.dylib, libxml2.dylib
5) 创建一个支付按钮
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) 使用以下代码实现按钮操作方法:
-(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) 使用跟随委托(delegate)
-(void)paymentSuccessWithKey:(NSString *)payKey andStatus:(PayPalPaymentStatus)paymentStatus
{
NSLog(@"Successfully Paid");
}
-(void)paymentCanceled
{
NSLog(@"Cancelled");
}
- (void)paymentFailedWithCorrelationID:(NSString *)correlationID
{
NSLog(@"Failed");
}
-(void)paymentLibraryExit
{
NSLog(@"Exit");
}
关于ios - 在 iOS 中处理对用户的付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12132206/