darwinpricing / darwinpricing-client
Darwin Pricing 动态地理定价引擎的PHP客户端
5.2.0
2016-05-24 14:46 UTC
Requires
- php: >=5.0.0
Requires (Dev)
README
由SPOSEA提供的Darwin Pricing动态地理定价引擎的PHP客户端
基本用法
在Darwin Pricing上创建一个免费账户。
使用您的API凭据实例化Darwin Pricing客户端
$serverUrl = 'https://api2.darwinpricing.com'; // Use the URL of your API server $clientId = 50000; // Use the client ID of your Darwin Pricing account $clientSecret = 'abcdef'; // Use the client secret of your Darwin Pricing account $darwinPricing = new \DarwinPricing_Client($serverUrl, $clientId, $clientSecret);
为了将我们的地理定位优惠券框添加到您的店面,检索前端脚本的URL
$widgetUrl = $darwinPricing->getWidgetUrl();
然后在您的网站上异步加载此脚本
<script>(function(d,t,s,f){s=d.createElement(t);s.src=<?php echo json_encode($widgetUrl); ?>;s.async=1;f=d.getElementsByTagName(t)[0];f.parentNode.insertBefore(s,f)})(document,'script')</script>
要跟踪支付和支付撤销,请使用
$customerIp = '134.3.197.187'; // Use the IP address of your customer $customer = new \DarwinPricing_Client_Visitor($customerIp); $darwinPricing->setVisitor($customer); $profitAmount = 12.34; // Compute your actual net profit for this payment $profitCurrencyCode = 'USD'; // Use the 3 letters code according to ISO 4217 $profit = new \DarwinPricing_Client_Price($profitAmount, $profitCurrencyCode); $darwinPricing->addPayment($profit);
Darwin Pricing会自动优化您的地理定价策略,以最大化您的总净利润。但您也可以根据当前的业务目标,最大化任何其他KPI。只需向我们发送适当的指标而不是净利润,您的地理定价策略将被相应优化。
订单详情
您可以直接将完整的订单详情发送到您的Darwin Pricing账户,而不仅仅是计算您的净利润。这样,您的Darwin Pricing账户将解锁增强的报告功能,如利润率和优惠券代码使用。
为了跟踪新订单,请使用
$order = new DarwinPricing_Client_Order(); $order->setCustomerIp('134.3.197.187'); // The IP address of your customer $order->setCustomerId('#12321'); // Your reference for this customer (optional) $order->setEmail('customer@example.com'); // The e-mail address of this customer (optional) $order->setOrderId('12345'); // The internal ID of this order in your eCommerce system $order->setOrderReference('#201612345'); // Your reference for this order (optional) $order->setCurrency('USD'); // The currency code for this order (3 letters code according to ISO 4217) // For each item sold: // - The unit price of this item (including VAT when applicable) // - The number of items sold for this order // - Your SKU for this item (optional) // - The item's internal product ID in your eCommerce system (optional) // - The item's internal variant ID in your eCommerce system (optional) // - Your average unit costs to purchase or produce this item (optional) // - The Value Added Tax rate in percent for this item (when applicable) $order->addItem(120.90, 3, 'A1234', '123', '456', 89.95, 19.5); $order->addCoupon('HAPPY10'); // The coupon code redeemed for this order (optional) $order->setShippingAmount(9.99); // The shipping costs billed to your customer (optional, including VAT when applicable) $order->setShippingVatRate(12.8); // The Value Added Tax rate in percent for the shipping costs (when applicable) $order->setTaxes(38.85); // The amount of sales tax (not VAT) for this order (when applicable) $order->setTotal(375.54); // The total amount billed to your customer (including taxes) $darwinPricing->trackOrder($order);
客户的电子邮件地址仅用于在通过图像代理(如Google Mail)加载时提供地理定位新闻通讯横幅。
自定义集成
除了将我们的地理定位优惠券框添加到您的店面外,您还可以使用以下方法从商店的后端检索地理定位优惠券代码
$visitorIp = '134.3.197.187'; // Use the IP address of your visitor $visitor = new \DarwinPricing_Client_Visitor($visitorIp); $darwinPricing->setVisitor($visitor); $discountPercent = $darwinPricing->getDiscountPercent(); $discountCode = $darwinPricing->getDiscountCode();
如果不想使用优惠券代码来调整直接价格以适应当地市场,这将特别有用。如果您正在销售基于订阅的产品,您还可以检索定价计划标识符而不是折扣代码。请联系我们support@darwinpricing.com以了解最适合您需求的最佳解决方案!