Exemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $authToken = $this->_scopeConfig->getValue('riskified/riskified/key', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $env = constant('\\Riskified\\Common\\Env::' . $this->_scopeConfig->getValue('riskified/riskified/env'));
     $domain = $this->_scopeConfig->getValue('riskified/riskified/domain');
     $output->writeln("Riskified auth token: {$authToken} \n");
     $output->writeln("Riskified shop domain: {$domain} \n");
     $output->writeln("Riskified target environment: {$env} \n");
     $output->writeln("*********** \n");
     Riskified::init($domain, $authToken, $env, Validations::SKIP);
     $orders = $this->_getEntireCollection();
     $total_count = count($orders);
     $output->writeln("Starting to upload orders, total_count: {$total_count} \n");
     $this->_getCollection();
     while ($this->_totalUploaded < $total_count) {
         try {
             $this->_postOrders();
             $this->_totalUploaded += count($this->_orders);
             $this->_currentPage++;
             $output->writeln("Uploaded " . $this->_totalUploaded . " of " . $total_count . " orders\n");
             $this->_getCollection();
         } catch (\Exception $e) {
             $output->writeln("<error>" . $e->getMessage() . "</error> \n");
             exit(1);
         }
     }
 }
Exemplo n.º 2
0
 public function initSdk()
 {
     $authToken = $this->_apiConfig->getAuthToken();
     $env = constant($this->_apiConfig->getConfigEnv());
     $shopDomain = $this->_apiConfig->getShopDomain();
     $this->version = $this->_apiConfig->getExtensionVersion();
     Riskified::init($shopDomain, $authToken, $env, Validations::SKIP);
 }
Exemplo n.º 3
0
 * permissions and limitations under the License.
 */
// An example of a complete order flow.
// Usage: php order_full_flow.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 = "[your shop domain as registered to Riskified]";
# Replace with the 'auth token' listed in the Riskified web app under the 'Settings' Tab
$authToken = "[your authentication token string]";
Riskified::init($domain, $authToken, Env::SANDBOX, Validations::ALL);
$order_details = array('id' => 'ch567', '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('*****@*****.**', '*****@*****.**', 'third!2@email.rr.com'), 'note' => 'Shipped to my hotel.', 'referring_site' => 'google.com', 'line_items' => array(new Model\LineItem(array('price' => 100, 'quantity' => 1, 'title' => 'ACME Widget', 'product_id' => '101', 'sku' => 'ABCD')), new Model\LineItem(array('title' => 'Giftcard', 'price' => 100, 'quantity' => 1, 'requires_shipping' => false, 'delivered_at' => '2017-03-10T11:00:00-05:00')), new Model\LineItem(array('price' => 200, 'quantity' => 4, 'title' => 'ACME Spring', 'product_id' => '202', 'sku' => 'EFGH', 'category' => 'ACME Spring Category', 'sub_category' => 'ACME Spring Sub Category'))), 'discount_codes' => new Model\DiscountCode(array('amount' => 19.95, 'code' => '12')), 'shipping_lines' => new Model\ShippingLine(array('title' => 'FedEx', 'price' => 123.0, 'code' => 'Free')), 'payment_details' => new Model\PaymentDetails(array('credit_card_bin' => '370002', 'credit_card_number' => 'xxxx-xxxx-xxxx-1234', 'credit_card_company' => 'VISA')), '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')), 'billing_address' => new Model\Address(array('first_name' => 'John', 'last_name' => 'Doe', 'address1' => '108 Main Street', 'company' => 'Kansas Computers', 'country' => 'United States', 'country_code' => 'US', 'phone' => '1234567', 'city' => 'NYC', 'name' => 'John Doe', 'address2' => 'Apartment 12', 'province' => 'New York', 'province_code' => 'NY', 'zip' => '64155')), 'shipping_address' => new Model\Address(array('first_name' => 'John', 'last_name' => 'Doe', 'address1' => '108 Main Street', 'company' => 'Kansas Computers', 'country' => 'United States', 'country_code' => 'US', 'phone' => '1234567', 'city' => 'NYC', 'name' => 'John Doe', 'address2' => 'Apartment 12', 'province' => 'New York', 'province_code' => 'NY', 'zip' => '64155')), 'charge_free_payment_details' => new Model\ChargeFreePaymentDetails(array('gateway' => 'giftcard', 'amount' => '50')));
# Create a curl transport to the Riskified Server
$transport = new Transport\CurlTransport(new Signature\HttpDataSignature());
$transport->timeout = 10;
#### Create Checkout
$checkout = new Model\Checkout($order_details);
$response = $transport->createCheckout($checkout);
echo PHP_EOL . "Create Checkout succeeded. Response: " . PHP_EOL . json_encode($response) . PHP_EOL;
#### Notify Checkout Denied
# $response = $transport->deniedCheckout($checkout);
# echo PHP_EOL . "Denied Checkout succeeded. Response: " . PHP_EOL . json_encode($response) . PHP_EOL;
#### Create and Submit Order
$order = new Model\Order($order_details);
$order->checkout_id = $order->id;
$order->id = 'or1234';
Exemplo n.º 4
0
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
// Router handler for callback server
// See run_callback_server.sh for usage
include __DIR__ . '/../src/Riskified/autoloader.php';
use Riskified\Common\Riskified;
use Riskified\Common\Signature;
use Riskified\DecisionNotification\Model;
# 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);
$signature = new Signature\HttpDataSignature();
$valid_headers = array($signature::HMAC_HEADER_NAME);
function map_keys($header, $value)
{
    $canonical_header = str_replace('HTTP-', '', str_replace('_', '-', strtoupper(trim($header))));
    return array($canonical_header => $value);
}
function reduce_keys($carry, $item)
{
    if (is_null($carry)) {
        $carry = array();
    }
    return array_merge($carry, $item);
}
$canonical_headers = array_reduce(array_map('map_keys', array_keys($_SERVER), $_SERVER), 'reduce_keys');
 * permissions and limitations under the License.
 */
// 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;
$helper = Mage::helper('full');
$authToken = $helper->getAuthToken();
$env = constant($helper->getConfigEnv());
$domain = $helper->getShopDomain();
echo "Riskified auth token: {$authToken} \n";
echo "Riskified shop domain: {$domain} \n";
echo "Riskified target environment: {$env} \n";
echo "*********** \n";
include __DIR__ . 'lib/riskified_php_sdk/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;
Riskified::init($domain, $authToken, $env, Validations::SKIP);
// add your own code below:
$batch_size = 10;
$options = getopt("p::");
$page = intval($options["p"]);
if (!$page) {
    $page = 1;
}
$orders = Mage::getModel('sales/order')->getCollection();
$total_count = $orders->getSize();
echo "starting to upload orders, total_count: {$total_count} \n";
$orders_collection = Mage::getModel('sales/order')->getCollection()->setPageSize($batch_size)->setCurPage($page);
$total_uploaded = 0;
while ($total_uploaded < $total_count) {
    $last_id = $orders_collection->getLastItem()->getEntityId();
    try {
Exemplo n.º 7
0
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
// A simple example of uploading historical orders from the command line.
// Usage: php upload_historical.php
include __DIR__ . '/../src/Riskified/autoloader.php';
use Riskified\Common\Riskified;
use Riskified\Common\Env;
use Riskified\Common\Signature;
use Riskified\OrderWebhook\Model;
use Riskified\OrderWebhook\Transport;
# Replace with the 'shop domain' of your account in Riskified
$domain = "[your shop domain as registered to Riskified]";
# Replace with the 'auth token' listed in the Riskified web app under the 'Settings' Tab
$authToken = "[your authentication token string]";
Riskified::init($domain, $authToken, Env::SANDBOX);
$first_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', 'note' => 'Shipped to my hotel.', 'referring_site' => 'google.com'));
$second_order = new Model\Order(array('id' => '1235', 'name' => '#1235', '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', 'note' => 'Shipped to my hotel.', 'referring_site' => 'google.com'));
$orders = array($first_order, $second_order);
# Create a curl transport to the Riskified Server
$transport = new Transport\CurlTransport(new Signature\HttpDataSignature());
$transport->timeout = 10;
try {
    $response = $transport->sendHistoricalOrders($orders);
    echo PHP_EOL . "Upload succeeded. Response: " . PHP_EOL . json_encode($response) . PHP_EOL;
} catch (\Riskified\OrderWebhook\Exception\UnsuccessfulActionException $uae) {
    echo PHP_EOL . "Upload failed. Status code was: " . $uae->statusCode . " and body was: " . json_encode($uae->jsonResponse) . PHP_EOL;
} catch (Exception $e) {
    echo PHP_EOL . "Upload failed. Exception: " . $e->getMessage() . PHP_EOL;
}
Exemplo n.º 8
0
 private function initSdk()
 {
     $helper = Mage::helper('full');
     $authToken = $helper->getAuthToken();
     $env = constant($helper->getConfigEnv());
     $shopDomain = $helper->getShopDomain();
     $this->version = $helper->getExtensionVersion();
     $sdkVersion = Riskified::VERSION;
     Mage::helper('full/log')->log("Riskified initSdk() - shop: {$shopDomain}, env: {$env}, token: {$authToken}, extension_version: {$this->version}, sdk_version: {$sdkVersion}");
     Riskified::init($shopDomain, $authToken, $env, Validations::SKIP);
 }