2013-10-03 49 views
0

我目前使用paypal PHP rest api 0.6。我無法設置折扣金額。如何在paypal php rest api中添加折扣信息?

我能看到物品清單,稅金和裝運金額。但不知道如何配置折扣。 $ payer = new Payer(); $ payer-> setPaymentMethod(「paypal」);

  $item = new Item(); 
      $item->setQuantity("1"); 
      $item->setName("Classic Shirt"); 
      $item->setPrice("100.00"); 
      $item->setCurrency("USD"); 
      $item->setSku("CS00001"); 
      $item2 = new Item(); 
      $item2->setQuantity("1"); 
      $item2->setName("Classic Brown Shirt"); 
      $item2->setPrice("100.00"); 
      $item2->setCurrency("USD"); 
      $item2->setSku("CS00002"); 

      $amount = new Amount(); 
      $amount->setCurrency("USD"); 

      $amountDetails = new Details(); 

      $amountDetails->setSubtotal('200'); 
      $amountDetails->setTax('10'); 
      $amountDetails->setShipping('10'); 
      //$amountDetails->setDiscount('10'); 
      $amount->setDetails($amountDetails); 
      $amount->setTotal("210.00"); 
      $item_list = new ItemList(); 
      $item_list->setItems(array($item,$item2)); 

      $transaction = new Transaction(); 
      $transaction->setAmount($amount); 
      $transaction->setDescription("This is incredibly awesome."); 
      $transaction->setItem_list($item_list); 

      $baseUrl = getBaseUrl(); 
      $redirectUrls = new RedirectUrls(); 
      $redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true") 
        ->setCancelUrl("$baseUrl/ExecutePayment.php?success=false"); 

      // ### Payment 
      // A Payment Resource; create one using 
      // the above types and intent set to 'sale' 
      $payment = new Payment(); 
      $payment->setIntent("sale") 
        ->setPayer($payer) 
        ->setRedirectUrls($redirectUrls) 
        ->setTransactions(array($transaction)); 
+0

沒有你解決這個問題? – danielwinter

回答

0

我在API reference的折扣中沒有看到任何提及。

我建議你簡單地自己計算折扣,並打折價格致電->setPrice

0

你爲什麼不加入一個負數,使描述折扣

+0

貝寶只允許項目的正值,所以這不起作用。 – danielwinter

3

在REST API的當前版本,你可以使用負值的折扣,例如:

$itemTmp = new \PayPal\Api\Item(); 
$itemTmp->setName('Discount') 
->setCurrency('EUR') 
->setQuantity(1) 
->setPrice(-10);