php - 如何在 paypal php rest api 中添加折扣信息?

标签 php paypal

我目前正在使用 paypal php rest api 0.6。我无法设置折扣金额。

我可以看到商品 list 、税金和装运金额。但不知道如何配置折扣。 $付款人=新付款人(); $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));

最佳答案

在当前版本的 REST API 中,您可以使用负值进行折扣,例如:

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

关于php - 如何在 paypal php rest api 中添加折扣信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19155703/

相关文章:

Paypal 订阅不同数量的项目

iphone - 我们可以通过从 iPhone 向 PayPal 服务器发送请求来获取预批准 key 吗? (供测试用)

php - 日期格式无法正常工作

php - Laravel 不显示数据

php - 跨子域和主机的 Cookie

php - 返回paypal中的商户问题

php - Paypal PHP API 集成

php - Laravel 数据库外观内存使用情况

php - esc_html_e() 中是否可以换行?

php - 以编程方式创建 magento 订单中的 Paypal 发布错误