public function validSend($data) { require_once DIR_SYSTEM . 'library/stelo/Stelo.php'; $this->load->model('account/customer'); $this->load->model('checkout/order'); $customer = $this->model_account_customer->getCustomer($data['customer_id']); $order_total = $this->model_checkout_order->getOrderTotal($this->session->data['order_id'], 'shipping'); $params = array(); $converter = new Converter(); //OrderData $orderData = new OrderData(); $orderData->setOrderId((string) $this->session->data['order_id']); $params['orderData'] = $converter->convertOrderData($orderData); //PaymentData $paymentData = new PaymentData(); $paymentData->setAmount((double) number_format($data['total'], 2, '.', '')); $paymentData->setDiscountAmount(''); $paymentData->setFreight((double) number_format($order_total['value'], 2, '.', '')); $paymentData->setMaxInstallment('4'); // CartData if ($this->cart->getProducts()) { foreach ($this->cart->getProducts() as $product) { $cartData = new CartDataCollection(); $cartData->setProductName($product['name']); $cartData->setProductPrice((double) number_format($product['price'], 2, '.', '')); $cartData->setProductQuantity($product['quantity']); $cartData->setProductSku(substr($product['model'], 0, 19)); $paymentData->setCartData($cartData); } } $params['paymentData'] = $converter->convertPaymentData($paymentData); //CustomerData $customerData = new CustomerData(); $customerData->setCustomerIdentity(str_replace('/', '', str_replace('-', '', str_replace('.', '', $data['cpf_cnpj'])))); $customerData->setCustomerName($data['firstname'] . ' ' . $data['lastname']); $customerData->setCustomerEmail($data['email']); $customerData->setBirthDay($customer['birthday']); $customerData->setGender($customer['sex']); // Billing Address $billingAddress = new BillingAddress(); $billingAddress->setStreet($data['payment_address_1']); $billingAddress->setNumber($data['payment_number_home']); $billingAddress->setComplement($data['payment_address_2']); $billingAddress->setNeighborhood($data['payment_neighborhood']); $billingAddress->setZipcode($data['payment_postcode']); $billingAddress->setCity($data['payment_city']); $billingAddress->setState($data['payment_zone_code']); $customerData->setBillingAddress($billingAddress); // Shipping Address $shippingAddress = new ShippingAddress(); $shippingAddress->setStreet($data['shipping_address_1']); $shippingAddress->setNumber($data['shipping_number_home']); $shippingAddress->setComplement($data['shipping_address_2']); $shippingAddress->setNeighborhood($data['shipping_neighborhood']); $shippingAddress->setZipcode($data['shipping_postcode']); $shippingAddress->setCity($data['shipping_city']); $shippingAddress->setState($data['shipping_zone_code']); $customerData->setShippingAddress($shippingAddress); // Phone Data $phoneData = new PhoneDataCollection(); $phoneData->setPhoneType("CELL"); $phoneData->setNumber(str_replace('(', '', str_replace(')', '', str_replace('-', '', str_replace(' ', '', $data['cellphone']))))); $customerData->setPhoneData($phoneData); $params['customerData'] = $converter->convertCustomerData($customerData); $params['changeShipment'] = false; //$url = 'http://200.142.203.223/ec/V1/wallet/transactions'; //Homologação $url = 'http://api.stelo.com.br/ec/V1/wallet/transactions'; $stelo = new Stelo(); $response = $stelo->sendRequest($url, $this->config->get('stelo_client_id'), $this->config->get('stelo_client_secret'), $params); $insert = "INSERT INTO " . DB_PREFIX . "transaction_stelo SET order_id = '" . $this->session->data['order_id'] . "', json_encode = '" . json_encode($params) . "', "; if ($response) { $insert .= "link_confirm = '" . $response['link'][0]['@href'] . "', link_cancel = '" . $response['link'][1]['@href'] . "', link_wallet = '" . $response['link'][2]['@href'] . "', order_stelo_id = '" . $response['orderData']['orderId'] . "', "; } $insert .= "date_added = NOW()"; $this->db->query($insert); return true; }