/**
  * Test for onOrderCreation event handler with wrong schutzclick response status
  */
 public function testOnOrderCreationWithWrongInsuranceResponseData()
 {
     $this->setExpectedException('Exception', 'Error when trying to create the transaction in Schutzklick.');
     $shopifyjsonString = '{"buyer_accepts_marketing":false,"cancel_reason":null,"cancelled_at":null,"cart_token":"ba20bbbd45694f2be71e9405cf43ca41","checkout_token":"029b01869d1974f5e72ac25c4ffa78e2","closed_at":null,"confirmed":true,"created_at":"2014-05-06T10:46:37-04:00","currency":"EUR","email":"*****@*****.**","financial_status":"pending","fulfillment_status":null,"gateway":"Vorkasse per \\u00dcberweisung","id":257868471,"landing_site":"\\/","location_id":null,"name":"#1009","note":"679545467:610:1","number":9,"reference":null,"referring_site":"","source":"browser","source_identifier":null,"source_name":"web","source_url":null,"subtotal_price":"168.99","taxes_included":true,"test":false,"token":"87fd273b4b68ef36e6c124728fa61e64","total_discounts":"0.00","total_line_items_price":"168.99","total_price":"178.99","total_price_usd":"248.35","total_tax":"3.19","total_weight":300,"updated_at":"2014-05-06T10:46:37-04:00","user_id":null,"browser_ip":null,"landing_site_ref":null,"order_number":1009,"discount_codes":[],"note_attributes":[],"processing_method":"manual","checkout_id":239939887,"tax_lines":[{"price":"3.19","rate":0.19,"title":"MwSt"}],"tags":"","line_items":[{"fulfillment_service":"manual","fulfillment_status":null,"grams":0,"id":457318931,"price":"19.99","product_id":288104311,"quantity":1,"requires_shipping":true,"sku":"605-275","taxable":true,"title":"1 Jahr Ger\\u00e4teschutz-Plus f\\u00fcr Smartphones","variant_id":679544487,"variant_title":"R250","vendor":"R+V","name":"1 Jahr Ger\\u00e4teschutz-Plus f\\u00fcr Smartphones - R250","variant_inventory_management":null,"properties":[],"product_exists":true,"tax_lines":[{"price":"3.19","rate":0.19,"title":"MwSt"}]},{"fulfillment_service":"manual","fulfillment_status":null,"grams":300,"id":457318935,"price":"149.00","product_id":288104867,"quantity":1,"requires_shipping":true,"sku":"0885909317776_4","taxable":false,"title":"Apple iPhone 3GS 32GB schwarz frei f\\u00fcr alle Netze","variant_id":679545467,"variant_title":"as good as new - wie neu","vendor":"Apple","name":"Apple iPhone 3GS 32GB schwarz frei f\\u00fcr alle Netze - as good as new - wie neu","variant_inventory_management":"shopify","properties":[],"product_exists":true,"tax_lines":[{"price":"0.00","rate":0.19,"title":"MwSt"}]}],"shipping_lines":[{"code":"Standard Shipping","price":"10.00","source":"shopify","title":"Standard Shipping","tax_lines":[{"price":"0.00","rate":0.19,"title":"MwSt"}]}],"billing_address":{"address1":"Schlesische Stra\\u00dfe 26","address2":"","city":"10997","company":"","country":"Germany","first_name":"Gabor","last_name":"Molnar","latitude":52.497799,"longitude":13.44795,"phone":"","province":"","zip":"Berlin","name":"Gabor Molnar","country_code":"DE","province_code":null},"shipping_address":{"address1":"Schlesische Stra\\u00dfe 26","address2":"","city":"10997","company":"","country":"Germany","first_name":"Gabor","last_name":"Molnar","latitude":52.497799,"longitude":13.44795,"phone":"","province":"","zip":"Berlin","name":"Gabor Molnar","country_code":"DE","province_code":null},"fulfillments":[],"client_details":{"accept_language":"de,en-US;q=0.7,en;q=0.3","browser_ip":"217.86.193.15","session_hash":"5a77a30dc9bf0181e256f056a0aa7cb7","user_agent":"Mozilla\\/5.0 (Macintosh; Intel Mac OS X 10.9; rv:28.0) Gecko\\/20100101 Firefox\\/28.0"},"customer":{"accepts_marketing":false,"created_at":"2014-04-22T07:47:55-04:00","email":"*****@*****.**","first_name":"Gabor","id":234459359,"last_name":"Molnar","last_order_id":257868471,"multipass_identifier":null,"note":null,"orders_count":4,"state":"disabled","total_spent":"799.72","updated_at":"2014-05-06T10:46:37-04:00","verified_email":true,"tags":"","last_order_name":"#1009","default_address":{"address1":"Schlesische Stra\\u00dfe 26","address2":"","city":"10997","company":"","country":"Germany","first_name":"Gabor","id":294133859,"last_name":"Molnar","phone":"","province":"","zip":"Berlin","name":"Gabor Molnar","province_code":null,"country_code":"DE","country_name":"Germany","default":true}}}';
     $schutzclickjsonString = '{"id":8205,"certificateNumber":100000008205,"certificateUrl":"https:\\/\\/sandbox.schutzklick.de\\/download\\/certificate\\/bb165b0c-835a-42b6-8dd1-d33b501d1ba0","status":"disabled"}';
     $this->_initMockClient($schutzclickjsonString);
     $schutzklickConnection = new SchutzklickConnection();
     $schutzklickConnection->setClient($this->clientMock);
     $logger = $this->getMockBuilder('Monolog\\Logger')->disableOriginalConstructor()->getMock();
     $schutzklickConnection->setLogger($logger);
     $schutzklickConnection->setUrl($schutzklickConnection->getClient()->getHttpClient()->getBaseUrl());
     $notifyevent = new ShopifyNotification();
     $notifyevent->receiveWebhook($shopifyjsonString);
     $result = $schutzklickConnection->onOrderCreation($notifyevent);
     $this->assertTrue($result);
 }
 /**
  * @param ShopifyNotification $event
  *
  * @return bool
  * @throws \Exception
  */
 public function onOrderCreation(ShopifyNotification $event, $handler = null)
 {
     $status = true;
     $schutzklickVendorName = "R+V";
     // check if we have the Schutzclick flag
     if ($event->hasVendorProducts($schutzklickVendorName)) {
         // get the real product title for the device
         $productTitles = $event->getBodyNonVendorProductTitles($schutzklickVendorName);
         foreach ($event->getBodyOnlyVendorProducts($schutzklickVendorName) as $body) {
             // get the response for the insurance creation
             $respInsurance = json_decode($this->createTransaction($body, array_shift($productTitles), $handler), true);
             $this->logger->addInfo("Resp. Insurance: " . print_r($respInsurance, true));
             // set the status
             $status = $status && isset($respInsurance['status']) && "activated" === $respInsurance['status'];
         }
     }
     if (!$status) {
         throw new \Exception("Error when trying to create the transaction in Schutzklick.");
     }
     return $status;
 }