-
-
Save nyalex/9004acbc4b2cabd5333b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// SET ENV KEYS | |
define('AWS_ACCESS_KEY_ID', 'REMOVED'); | |
define('AWS_SECRET_ACCESS_KEY', 'REMOVED'); | |
require 'aws-autoloader.php'; | |
use Aws\DynamoDb\Marshaler; | |
use Aws\DynamoDb\DynamoDbClient; | |
// Connect to DynamoDB | |
$client = DynamoDbClient::factory( | |
array( | |
'key' => AWS_ACCESS_KEY_ID, | |
'secret' => AWS_SECRET_ACCESS_KEY, | |
'region' => 'us-east-1' | |
) | |
); | |
// JSON to send | |
$order_json = '{"buyer_accepts_marketing":true,"cancel_reason":null,"cancelled_at":null,"cart_token":"9dd2641f4b4acfb049b18fec7d646454","checkout_token":"ba6d916933dec95ffd5043ff88eadeed","closed_at":null,"confirmed":true,"created_at":"2014-10-27T16:40:03-04:00","currency":"CAD","email":"asldfjk@aol.com","financial_status":"paid","fulfillment_status":null,"gateway":"bogus","id":347369045,"landing_site":"\/?rfsn=33469.8f8c&alex=1","location_id":null,"name":"#1511","note":"","number":511,"processed_at":"2014-10-27T16:40:03-04:00","reference":null,"referring_site":"","source_identifier":null,"source_name":"web","source_url":null,"subtotal_price":"19.00","taxes_included":false,"test":true,"token":"052298dec871bca9ba51108199f807d1","total_discounts":"0.00","total_line_items_price":"19.00","total_price":"39.95","total_price_usd":"35.54","total_tax":"0.95","total_weight":0,"updated_at":"2014-10-27T16:40:04-04:00","user_id":null,"browser_ip":"71.172.79.103","landing_site_ref":null,"order_number":1511,"discount_codes":[],"note_attributes":[],"processing_method":"direct","source":"browser","checkout_id":389426873,"tax_lines":[{"price":"0.95","rate":0.05,"title":"VAT"}],"tags":"","line_items":[{"fulfillment_service":"manual","fulfillment_status":null,"gift_card":false,"grams":0,"id":618708837,"price":"19.00","product_id":106025130,"quantity":1,"requires_shipping":true,"sku":"skualex","taxable":true,"title":"Customer-focused 24\/7 extranet","variant_id":243066656,"variant_title":"Medium","vendor":"Shopify","name":"Customer-focused 24\/7 extranet - Medium","variant_inventory_management":"shopify","properties":[],"product_exists":true,"fulfillable_quantity":1,"tax_lines":[{"price":"0.95","rate":0.05,"title":"VAT"}]}],"shipping_lines":[{"code":"International Shipping","price":"20.00","source":"shopify","title":"International Shipping","tax_lines":[{"price":"0.00","rate":0.05,"title":"VAT"}]}],"billing_address":{"address1":"123 Street Road","address2":"Suite 123","city":"New York","company":"Testing","country":"United States","first_name":"Testing","last_name":"Testing","latitude":40.729781,"longitude":-73.976017,"phone":"2122425252","province":"New York","zip":"10010","name":"Testing Testing","country_code":"US","province_code":"NY"},"shipping_address":{"address1":"123 Street Road","address2":"Suite 123","city":"New York","company":"Testing","country":"United States","first_name":"Testing","last_name":"Testing","latitude":40.729781,"longitude":-73.976017,"phone":"2122425252","province":"New York","zip":"10010","name":"Testing Testing","country_code":"US","province_code":"NY"},"fulfillments":[],"client_details":{"accept_language":"en-US,en;q=0.8","browser_height":null,"browser_ip":"71.172.79.103","browser_width":null,"session_hash":"79ae0b45aee94dd0ad47a5119f6e80368b08c48628cc340d3254f8dd0f0c8bde","user_agent":"Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/38.0.2125.104 Safari\/537.36"},"refunds":[],"payment_details":{"avs_result_code":null,"credit_card_bin":"1","cvv_result_code":null,"credit_card_number":"\u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 1","credit_card_company":"Bogus"},"customer":{"accepts_marketing":true,"created_at":"2014-09-15T20:43:10-04:00","email":"asldfjk@aol.com","first_name":"Testing","id":317797721,"last_name":"Testing","last_order_id":null,"multipass_identifier":null,"note":null,"orders_count":0,"state":"disabled","total_spent":"0.00","updated_at":"2014-10-27T16:40:04-04:00","verified_email":true,"tags":"","last_order_name":null,"default_address":{"address1":"123 Street Road","address2":"Suite 123","city":"New York","company":"Testing","country":"United States","first_name":"Testing","id":383875733,"last_name":"Testing","phone":"2122425252","province":"New York","zip":"10010","name":"Testing Testing","province_code":"NY","country_code":"US","country_name":"United States","default":true}}}'; | |
$order_json = str_replace('""', 'null', $order_json); | |
// Convert JSON for AWS | |
$m = new Marshaler(); | |
$order_json = $m->marshalJson($order_json); | |
// Send to DynamoDB | |
$result = $client->putItem(array( | |
'TableName' => 'test', | |
'Item' => array($order_json), | |
'ReturnConsumedCapacity' => 'TOTAL' | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment