2017-02-02 9 views
0

iOSのPayPal SDKを使用しています。 1つの製品の総量をpayPal SDKに渡すと、完全に機能します。しかし、カート内に1つ以上の商品があり、各商品の金額と数量が異なる場合は、合計金額をPayPalに引き渡す方法を教えてください。私がそれから出るのを助けてください。私は "ユーロ"通貨形式で価格を計算して渡しています。前もって感謝します。私のコードは次のとおりです。 -価格と商品の合計を取得し、Paypalに送信するiOS

 - (IBAction)paypalButtonForSubmitData:(id)sender 
     { 
      NSDecimalNumber *subTotal;  
      NSArray *items;  
      self.resultText = nil;  
    // Here _arrayToCarryDataFromCartToPaymentPageInPaypal is array through which I am getting data from Plist.   
     for (int j=0; j<_arrayToCarryDataFromCartToPaymentPageInPaypal.count; j++) 
      { 
       NSMutableDictionary *paypalArrayDataInDictionary=[_arrayToCarryDataFromCartToPaymentPageInPaypal objectAtIndex:j];  
// priceDetail is giving me the price of any particular product. 
       NSString *priceDetail=[paypalArrayDataInDictionary objectForKey:@"PRICE"];  
       NSString *stringWithoutSpaces = [priceDetail stringByReplacingOccurrencesOfString:@"€" withString:@""]; 
       NSLog(@"Price=%@",stringWithoutSpaces); 
       PayPalItem *item1=[PayPalItem itemWithName:@"IPHONE" withQuantity:[[paypalArrayDataInDictionary objectForKey:@"STOCK"]intValue] withPrice:[NSDecimalNumber decimalNumberWithString:stringWithoutSpaces] withCurrency:@"EUR" withSku:@"SKU-iPhone6"];  
       items= @[item1];  
       subTotal=[PayPalItem totalPriceForItems:items];  
       NSDecimalNumber *shipping=[[NSDecimalNumber alloc]initWithString:@"0,00"]; 
       NSDecimalNumber *tax=[[NSDecimalNumber alloc]initWithString:@"0,00"];  

       PayPalPaymentDetails *paymentDetails=[PayPalPaymentDetails paymentDetailsWithSubtotal:subTotal withShipping:shipping withTax:tax];  
       NSDecimalNumber *total=[[subTotal decimalNumberByAdding:shipping]decimalNumberByAdding:tax];  

       PayPalPayment *payment=[[PayPalPayment alloc]init];  
       payment.amount=total;  
       [email protected]"EUR";  
       [email protected]"My Payment";  
       payment.items=items;  
       payment.intent = PayPalPaymentIntentSale;  
       payment.paymentDetails=paymentDetails;  
       NSLog(@"Payment=%@",payment);  

       if (!payment.processable) {  
        NSLog(@"Error");  
       } 
       // self.payPalConfig.acceptCreditCards=self.acceptCreditCards;  
       PayPalPaymentViewController *paymentViewController=[[PayPalPaymentViewController alloc]initWithPayment:payment configuration:self.payPalConfig delegate:self];  
       [self presentViewController:paymentViewController animated:true completion:nil];  
      }  
     }  

答えて

0

あなたがループを開始する前に、コードの下に

PayPalPayment *payment=[[PayPalPayment alloc]init]; 

を宣言する必要があり、このため

のforループの外にPaypalViewControllerを提示するコードを記述してください。

編集したコードの下にご返信用

- (IBAction)paypalButtonForSubmitData:(id)sender 
    { 
     NSDecimalNumber *subTotal;  
     NSArray *items;  
     self.resultText = nil;  
// Here _arrayToCarryDataFromCartToPaymentPageInPaypal is array through which I am getting data from Plist.   
    for (int j=0; j<_arrayToCarryDataFromCartToPaymentPageInPaypal.count; j++) 
     { 
      NSMutableDictionary *paypalArrayDataInDictionary=[_arrayToCarryDataFromCartToPaymentPageInPaypal objectAtIndex:j];  
      // priceDetail is giving me the price of any particular product. 
      NSString *priceDetail=[paypalArrayDataInDictionary objectForKey:@"PRICE"];  
      NSString *stringWithoutSpaces = [priceDetail stringByReplacingOccurrencesOfString:@"€" withString:@""]; 
      NSLog(@"Price=%@",stringWithoutSpaces); 
      PayPalItem *item1=[PayPalItem itemWithName:@"IPHONE" withQuantity:[[paypalArrayDataInDictionary objectForKey:@"STOCK"]intValue] withPrice:[NSDecimalNumber decimalNumberWithString:stringWithoutSpaces] withCurrency:@"EUR" withSku:@"SKU-iPhone6"];  
      items= @[item1];  
     } 
      subTotal=[PayPalItem totalPriceForItems:items];  
      NSDecimalNumber *shipping=[[NSDecimalNumber alloc]initWithString:@"0,00"]; 
      NSDecimalNumber *tax=[[NSDecimalNumber alloc]initWithString:@"0,00"];  

      PayPalPaymentDetails *paymentDetails=[PayPalPaymentDetails paymentDetailsWithSubtotal:subTotal withShipping:shipping withTax:tax];  
      NSDecimalNumber *total=[[subTotal decimalNumberByAdding:shipping]decimalNumberByAdding:tax];  

      PayPalPayment *payment=[[PayPalPayment alloc]init];  
      payment.amount=total;  
      [email protected]"EUR";  
      [email protected]"My Payment";  
      payment.items=items;  
      payment.intent = PayPalPaymentIntentSale;  
      payment.paymentDetails=paymentDetails;  
      NSLog(@"Payment=%@",payment);  

      if (!payment.processable) {  
       NSLog(@"Error");  
      } 
      // self.payPalConfig.acceptCreditCards=self.acceptCreditCards;  
      PayPalPaymentViewController *paymentViewController=[[PayPalPaymentViewController alloc]initWithPayment:payment configuration:self.payPalConfig delegate:self];  
      [self presentViewController:paymentViewController animated:true completion:nil];   
    }  
+0

感謝をしてみてください。しかし、それはカート内で利用可能な製品の合計価格を与えているわけではありません(10個の製品を想定しています)。これを行う方法 ? –

+0

@AbhishekSharma - 改訂コード – Firoj

+0

を以前と同じように確認してください。製品の総価格を指定していない。 –

関連する問題