// A simple example of submitting an order. // Usage: php order_simple_submit.php include __DIR__ . '/../src/Riskified/autoloader.php'; use Riskified\Common\Riskified; use Riskified\Common\Env; use Riskified\Common\Validations; use Riskified\Common\Signature; use Riskified\OrderWebhook\Model; use Riskified\OrderWebhook\Transport; # Replace with the 'shop domain' of your account in Riskified $domain = "test.com"; # Replace with the 'auth token' listed in the Riskified web app under the 'Settings' Tab $authToken = "1388add8a99252fc1a4974de471e73cd"; Riskified::init($domain, $authToken, Env::SANDBOX, Validations::IGNORE_MISSING); # Order $order = new Model\Order(array('id' => '1234', 'name' => '#1234', 'email' => '*****@*****.**', 'created_at' => '2010-01-10T11:00:00-05:00', 'closed_at' => null, 'currency' => 'CAD', 'updated_at' => '2010-01-10T11:00:00-05:00', 'gateway' => 'mypaymentprocessor', 'browser_ip' => '124.185.86.55', 'total_price' => 113.23, 'total_discounts' => 5.0, 'cart_token' => '1sdaf23j212', 'additional_emails' => array('*****@*****.**', '*****@*****.**'), 'note' => 'Shipped to my hotel.', 'referring_site' => 'google.com')); # LineItems $lineItem1 = new Model\LineItem(array('price' => 100, 'quantity' => 1, 'title' => 'ACME Widget', 'product_id' => '101', 'sku' => 'ABCD')); $lineItem2 = new Model\LineItem(array('price' => 200, 'quantity' => 4, 'title' => 'ACME Spring', 'product_id' => '202', 'sku' => 'EFGH')); $order->line_items = array($lineItem1, $lineItem2); # DiscountCodes $discountCode = new Model\DiscountCode(array('amount' => 19.95, 'code' => '12')); $order->discount_codes = $discountCode; # ShippingLines $shippingLine = new Model\ShippingLine(array('price' => 123.0, 'code' => 'Free')); $order->shipping_lines = $shippingLine; # PaymentDetais $paymentDetails = new Model\PaymentDetails(array('credit_card_bin' => '370002', 'avs_result_code' => 'Y', 'cvv_result_code' => 'N', 'credit_card_number' => 'xxxx-xxxx-xxxx-1234', 'credit_card_company' => 'VISA')); $order->payment_details = $paymentDetails; # Customer $customer = new Model\Customer(array('email' => '*****@*****.**', 'first_name' => 'Firstname', 'last_name' => 'Lastname', 'id' => '1233', 'created_at' => '2008-01-10T11:00:00-05:00', 'orders_count' => 6, 'verified_email' => true, 'account_type' => 'free'));
private function getOrder($model) { $gateway = 'unavailable'; if ($model->getPayment()) { $gateway = $model->getPayment()->getMethod(); } $order_array = array('id' => $this->getOrderOrigId($model), 'name' => $model->getIncrementId(), 'email' => $model->getCustomerEmail(), 'created_at' => $this->formatDateAsIso8601($model->getCreatedAt()), 'currency' => $model->getOrderCurrencyCode(), 'updated_at' => $this->formatDateAsIso8601($model->getUpdatedAt()), 'gateway' => $gateway, 'browser_ip' => $this->getRemoteIp($model), 'cart_token' => Mage::helper('full')->getSessionId(), 'note' => $model->getCustomerNote(), 'total_price' => $model->getGrandTotal(), 'total_discounts' => $model->getDiscountAmount(), 'subtotal_price' => $model->getBaseSubtotalInclTax(), 'discount_codes' => $this->getDiscountCodes($model), 'taxes_included' => true, 'total_tax' => $model->getBaseTaxAmount(), 'total_weight' => $model->getWeight(), 'cancelled_at' => $this->formatDateAsIso8601($this->getCancelledAt($model)), 'financial_status' => $model->getState(), 'fulfillment_status' => $model->getStatus(), 'vendor_id' => $model->getStoreId(), 'vendor_name' => $model->getStoreName()); if (Mage::getSingleton('admin/session')->isLoggedIn()) { unset($order_array['browser_ip']); unset($order_array['cart_token']); } $order = new Model\Order(array_filter($order_array, 'strlen')); $order->customer = $this->getCustomer($model); $order->shipping_address = $this->getShippingAddress($model); $order->billing_address = $this->getBillingAddress($model); $order->payment_details = $this->getPaymentDetails($model); $order->line_items = $this->getLineItems($model); $order->shipping_lines = $this->getShippingLines($model); if (!Mage::getSingleton('admin/session')->isLoggedIn()) { $order->client_details = $this->getClientDetails($model); } Mage::helper('full/log')->log("getOrder(): " . PHP_EOL . json_encode(json_decode($order->toJson()))); return $order; }