From 634b230a329bd8be2fcf3a5a6e757b12481428c5 Mon Sep 17 00:00:00 2001 From: Alexander Zinovev Date: Thu, 11 Apr 2019 14:31:31 +0200 Subject: [PATCH] Examples: Add example "How to set discount". --- docs/examples/CheckoutAPI/discounts.php | 93 +++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 docs/examples/CheckoutAPI/discounts.php diff --git a/docs/examples/CheckoutAPI/discounts.php b/docs/examples/CheckoutAPI/discounts.php new file mode 100644 index 0000000..1ba78e0 --- /dev/null +++ b/docs/examples/CheckoutAPI/discounts.php @@ -0,0 +1,93 @@ + "gb", + "purchase_currency" => "gbp", + "locale" => "en-gb", + "order_amount" => 9000, + "order_tax_amount" => 818, + "order_lines" => [ + [ + "type" => "physical", + "reference" => "19-402-USA", + "name" => "Red T-Shirt", + "quantity" => 1, + "quantity_unit" => "pcs", + "unit_price" => 10000, + "tax_rate" => 1000, + "total_amount" => 10000, + "total_tax_amount" => 909 + ], + + // Add discount as an order line + [ + "type" => "discount", + "reference" => "10-gbp-order-discount", + "name" => "Discount", + "quantity" => 1, + "unit_price" => -1000, + "tax_rate" => 1000, + "total_amount" => -1000, + "total_tax_amount" => -91 + ] + ], + "merchant_urls" => [ + "terms" => "https://example.com/toc", + "checkout" => "https://example.com/checkout?klarna_order_id={checkout.order.id}", + "confirmation" => "https://example.com/thank-you?klarna_order_id={checkout.order.id}", + "push" => "https://example.com/create_order?klarna_order_id={checkout.order.id}" + ] +]; + +try { + $checkout = new Klarna\Rest\Checkout\Order($connector); + $checkout->create($order); + + echo $checkout['html_snippet']; +} catch (Exception $e) { + echo 'Caught exception: ' . $e->getMessage() . "\n"; +}