private function createPayment($user, $tariff, $beginningDate, $lang) { $userId = $user['id_user']; $tariffId = $tariff['id_tariff']; $tariffName = $this->getTariffName($tariffId, 'cs'); //invoice is in czech only $priceCZK = $tariff['priceCZK']; $fakturoid = new FakturoidWrapper(); $fakturoidInvoice = $fakturoid->createInvoice($user, $tariff['priceCZK'], $tariffName, $beginningDate, $lang); if (!$fakturoidInvoice) { return ['s' => 'error', 'cs' => 'Nepovedlo se spojení s fakturoid.cz. Zkuste to prosím za pár minut', 'en' => 'We are unable to connect to fakturoid.cz. Try again in a few minutes']; } $fakturoidInvoiceId = $fakturoidInvoice->id; $fakturoidInvoiceNumber = $fakturoidInvoice->number; $now = date('Y-m-d H-i-s'); Db::queryModify(' INSERT INTO `payments` ( `id_payer`, `payment_first_date`, `status`, `time_generated`, `tariff_id`, `price_CZK`, `invoice_fakturoid_id`, `invoice_fakturoid_number` ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', [$userId, date('Y-m-d', $beginningDate), 'unpaid', $now, $tariffId, $priceCZK, $fakturoidInvoiceId, $fakturoidInvoiceNumber]); //add blank extras $extras = new Extras(); $blankExtras = $extras->getBlankExtras($user['id_user']); if (!empty($blankExtras)) { foreach ($blankExtras as $extra) { $extraId = $extra['id_extra']; $price = $extra['priceCZK']; $description = $extra['description']; $fakturoidExtraId = $fakturoid->addExtra($fakturoidInvoiceId, $extra['priceCZK'], $extra['description']); $paymentId = $this->getPaymentIdFromFakturoidInvoiceId($fakturoidInvoiceId); $extras->assignBlankExtra($paymentId, $price, $description, $fakturoidExtraId, $extraId); } } //send email to user $subject = NAME . ' Paralelní Polis - nová faktura'; $link = ROOT . '/cs/payments'; $message = 'Ahoj,<br/> <br/> vystavili jsem ti fakturu za členství / pronájem v Paper Hub v Paralelní Polis.<br/> <a href="' . $link . '">' . $link . '</a><br/> Platbu uhradíš jednoduše na odkazu výše.<br/> <br/> Díky za rychlou platbu!<br/> Paper Hub'; $this->sendEmail(EMAIL, $user['email'], $subject, $message); //and send copy of email to hub manager //TODO refractor $this->sendEmail(EMAIL, EMAIL_HUB_MANAGER, NAME . ' - Poslána výzva o nové faktuře na email ' . $user['email'], $message); return ['s' => 'success']; }
private function createPayment($user, $tariff, $beginningDate, $lang) { $userId = $user['id_user']; $tariffId = $tariff['id_tariff']; $tariffName = $this->getTariffName($tariffId, $lang); $priceCZK = $tariff['priceCZK']; $fakturoid = new FakturoidWrapper(); $fakturoidInvoice = $fakturoid->createInvoice($user, $tariff['priceCZK'], $tariffName, $beginningDate); if (!$fakturoidInvoice) { return ['s' => 'error', 'cs' => 'Nepovedlo se spojení s fakturoid.cz. Zkuste to prosím za pár minut', 'en' => 'We cannot connect into fakturoid.cz. Try it again in a few minutes please']; } $fakturoidInvoiceId = $fakturoidInvoice->id; $fakturoidInvoiceNumber = $fakturoidInvoice->number; Db::queryModify(' INSERT INTO `payments` ( `id_payer`, `payment_first_date`, `status`, `time_generated`, `tariff_id`, `price_CZK`, `invoice_fakturoid_id`, `invoice_fakturoid_number` ) VALUES (?, ?, ?, NOW(), ?, ?, ?, ?)', [$userId, $beginningDate, 'unpaid', $tariffId, $priceCZK, $fakturoidInvoiceId, $fakturoidInvoiceNumber]); return ['s' => 'success']; }