/** * This function is likely never returns * but anyway handle result and exceptions * @return Am_Paysystem_Result */ function process() { $err = $this->invoice->validate(); if ($err) { throw new Am_Exception_InputError($err[0]); } $this->invoice->save(); $plugin = Am_Di::getInstance()->plugins_payment->loadGet($this->invoice->paysys_id); $this->result = new Am_Paysystem_Result(); $plugin->processInvoice($this->invoice, $this->controller->getRequest(), $this->result); if ($this->result->isSuccess() || $this->result->isFailure()) { if ($transaction = $this->result->getTransaction()) { $transaction->setInvoice($this->invoice); $transaction->process(); } } if ($this->result->isSuccess()) { $url = REL_ROOT_URL . "/thanks?id=" . $this->invoice->getSecureId('THANKS'); $this->callback($this->onSuccess); $this->controller->redirectLocation($url, ___("Invoice processed"), ___("Invoice processed successfully")); // no return Am_Exception_Redirect } elseif ($this->result->isAction()) { $this->callback($this->onAction); $this->result->getAction()->process($this->controller); // no return Am_Exception_Redirect } else { // ($result->isFailure()) { $this->callback($this->onFailure); } return $this->result; }
/** * This function is likely never returns * but anyway handle result and exceptions * @return Am_Paysystem_Result */ function process() { Am_Di::getInstance()->hook->call(Am_Event::INVOICE_BEFORE_PAYMENT, array('invoice' => $this->invoice, 'controller' => $this->controller)); $plugin = Am_Di::getInstance()->plugins_payment->loadGet($this->invoice->paysys_id); $this->result = new Am_Paysystem_Result(); $plugin->processInvoice($this->invoice, $this->controller->getRequest(), $this->result); if ($this->result->isSuccess() || $this->result->isFailure()) { if ($transaction = $this->result->getTransaction()) { $transaction->setInvoice($this->invoice); $transaction->process(); } } if ($this->result->isSuccess()) { if (method_exists($this->controller, 'getForm')) { $this->controller->getForm()->getSessionContainer()->destroy(); } $url = REL_ROOT_URL . "/thanks?id=" . $this->invoice->getSecureId('THANKS'); $this->callback($this->onSuccess); $this->controller->redirectLocation($url); // no return // Am_Exception_Redirect only for APPLICATION_ENV = 'testing' } elseif ($this->result->isAction()) { if (method_exists($this->controller, 'getForm')) { $this->controller->getForm()->getSessionContainer()->destroy(); } $this->callback($this->onAction); $this->result->getAction()->process($this->controller); // no return // Am_Exception_Redirect only for APPLICATION_ENV = 'testing' } else { // ($result->isFailure()) { $this->callback($this->onFailure); } return $this->result; }
public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { include_once dirname(__FILE__) . '/SOPGClassicMerchantClient.php'; $client = new SOPGClassicMerchantClient($this->getConfig('testing') ? self::TEST_API_URL : self::LIVE_API_URL); $mtid = $invoice->public_id; //$this->generateMtid(); // SEE par.2 if ($invoice->first_total > 1000) { throw new InvalidArgumentException('The maximum amount value of dispositions is 1000.00'); } // see par.2 $request = array($this->getConfig('login'), $this->getConfig('password'), $mtid, null, sprintf('%.2f', $invoice->first_total), $invoice->currency, urlencode($this->getReturnUrl()), urlencode($this->getPluginUrl('cancelpaysafecart') . "?id=" . $invoice->getSecureId('CANCEL')), $invoice->getUserId(), urlencode($this->getPluginUrl()), null); $this->logRequest($request); $response = call_user_func_array(array($client, 'createDisposition'), $request); $this->logResponse(get_object_vars($response)); if ($response->resultCode != 0 || $response->errorCode != 0) { // SEE par.4 $result->setErrorMessages(array('Transaction could not be initiated due to connection problems.')); //$result->setErrorMessages(array('Error during request to paysafecard server')); // see par.4 return; } $a = new Am_Paysystem_Action_Redirect($this->getConfig('testing') ? self::TEST_REDIRECT_URL : self::LIVE_REDIRECT_URL); $a->mid = $response->mid; $a->mtid = $mtid; $a->amount = sprintf('%.2f', $invoice->first_total); $a->currency = $invoice->currency; $result->setAction($a); }
public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { $req = $this->createHttpRequest(); $req->setUrl(self::POST_URL); $req->addPostParameter('Key', $this->getConfig('app_key')); $req->addPostParameter('Secret', $this->getConfig('app_secret')); $req->addPostParameter('DestinationId', $this->getConfig('destination_id')); $req->addPostParameter('OrderId', $invoice->public_id); $req->addPostParameter('Amount', $invoice->first_total); $req->addPostParameter('Test', $this->getConfig('testing') ? 'true' : 'false'); $req->addPostParameter('Redirect', $this->getPluginUrl('thanks') . '?id=' . $invoice->getSecureId('THANKS')); $req->addPostParameter('Name', $this->getDi()->config->get('site_title')); $req->addPostParameter('Description', $invoice->getLineDescription()); $req->addPostParameter('Callback', $this->getPluginUrl('ipn')); $this->logRequest($req); $req->setMethod(Am_HttpRequest::METHOD_POST); $response = $req->send(); $this->logResponse($response); $resp = $response->getBody(); if (strstr($resp, "Invalid+application+credentials")) { $result->setFailed("Invalid Application Credentials."); return; } elseif (strstr($resp, "error")) { $result->setFailed("Invalid Response From Dwolla's server."); return; } $i = strpos($resp, "checkout/"); $checkout_id = substr($resp, $i + 9, 36); $a = new Am_Paysystem_Action_Redirect(self::REDIRECT_URL . $checkout_id); $result->setAction($a); }
public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { $user = $invoice->getUser(); $vars = array('INAME' => 'purchase', 'Mer' => $this->getConfig('merchant_desc'), 'MerchantID' => $this->getConfig('merchant_id'), 'TransactionID' => $invoice->public_id, 'UserDesc' => strlen($desc = $invoice->getLineDescription()) > 256 ? substr($desc, 0, 253) . "..." : $desc, 'Amount' => $invoice->first_total, 'Currency' => $invoice->currency, 'itemType' => $this->getConfig('is_adult', false) ? 1 : 3, 'SuccessUserPage' => $this->getPluginUrl('thanks'), 'FailureUserPage' => $this->getCancelUrl(), 'MerchantData' => $invoice->getSecureId(self::SECURE_STRING . $invoice->first_total), 'ResultPageMethod' => 'POST', 'settleImmediate' => 1, 'FirstName' => $user->name_f, 'LastName' => $user->name_l, 'email' => $user->email, 'Address' => $user->street, 'City' => $user->city, 'postCode' => $user->zip, 'Country' => $user->country, 'State' => $user->state, 'Telephone' => $user->phone); $this->logRequest($vars); $action = new Am_Paysystem_Action_Form($this->getConfig('test_mode') ? self::URL_PAY_TEST : self::URL_PAY_LIVE); foreach ($vars as $key => $value) { $action->{$key} = $value; } $result->setAction($action); }
public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { $user = $invoice->getUser(); $subaccount_id = $invoice->getItem(0)->getBillingPlanData("ccbill_subaccount_id") ? $invoice->getItem(0)->getBillingPlanData("ccbill_subaccount_id") : $this->getConfig('subaccount_id'); $a = new Am_Paysystem_Action_Redirect(self::URL); $a->clientAccnum = $this->getConfig('account'); $a->clientSubacc = $subaccount_id; $a->formName = $invoice->getItem(0)->getBillingPlanData("ccbill_form_id"); $a->username = $user->login; $a->email = $invoice->getEmail(); $a->customer_fname = $invoice->getFirstName(); $a->customer_lname = $invoice->getLastName(); $a->address1 = $invoice->getStreet(); $a->city = $invoice->getCity(); $a->state = $invoice->getState(); $a->zipcode = $invoice->getZip(); $a->country = $invoice->getCountry(); $a->phone_number = $invoice->getPhone(); $a->payment_id = $invoice->public_id; $a->customVar1 = $invoice->public_id; $a->invoice = $invoice->getSecureId("THANKS"); $a->referer = $invoice->getUser()->aff_id; if ($this->getConfig('dynamic_pricing')) { $a->formPrice = $invoice->first_total; $a->formPeriod = $this->getDays($invoice->first_period); $a->currencyCode = $invoice->currency; if ($invoice->rebill_times) { if ($invoice->rebill_times == IProduct::RECURRING_REBILLS) { $invoice->rebill_times = 99; } $a->formRecurringPrice = $invoice->second_total; $a->formRecurringPeriod = $this->getDays($invoice->second_period); $a->formRebills = $invoice->rebill_times; $a->formDigest = md5($s = $invoice->first_total . $this->getDays($invoice->first_period) . $invoice->second_total . $this->getDays($invoice->second_period) . $invoice->rebill_times . $invoice->currency . $this->getConfig('salt')); } else { $a->formDigest = md5($s = $invoice->first_total . $this->getDays($invoice->first_period) . $invoice->currency . $this->getConfig('salt')); } } else { $a->subscriptionTypeId = $invoice->getItem(0)->getBillingPlanData("ccbill_product_id"); $a->allowedTypes = $invoice->getItem(0)->getBillingPlanData("ccbill_product_id"); $a->allowedCurrencies = $this->currency_codes[$invoice->currency]; } $result->setAction($a); }
public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { $req = new Am_HttpRequest(self::LIVE_URL, Am_HttpRequest::METHOD_POST); $req->addPostParameter(array('method' => 'create', 'address' => $this->getConfig('address'), 'callback' => $this->getPluginUrl('ipn') . "?secret=" . $invoice->getSecureId('THANKS') . '&invoice_id=' . $invoice->public_id)); $res = $req->send(); $arr = (array) json_decode($res->getBody(), true); if (empty($arr['input_address'])) { throw new Am_Exception_InternalError($res->getBody()); } $req = new Am_HttpRequest(self::CURRENCY_URL . "?currency={$invoice->currency}&value={$invoice->first_total}", Am_HttpRequest::METHOD_GET); $res = $req->send(); $amount = $res->getBody(); if (doubleval($amount) <= 0) { throw new Am_Exception_InternalError($amount); } $invoice->data()->set(self::BLOCKHAIN_AMOUNT, doubleval($amount))->update(); $a = new Am_Paysystem_Action_HtmlTemplate_Blockchain($this->getDir(), 'confirm.phtml'); $a->amount = doubleval($amount); $a->input_address = $arr['input_address']; $a->invoice = $invoice; $result->setAction($a); }
public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { $action = new Am_Paysystem_Action_Redirect($this->getPluginUrl(self::ACTION_CC)); $action->cc_id = $invoice->getSecureId($this->getId()); $result->setAction($action); }
/** * Display Thanks page for given Invoice */ protected function displayThanks(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs, Invoice $invoice = null) { if ($invoice !== null) { $request->setParam('id', $invoice->getSecureId('THANKS')); } /// require_once APPLICATION_PATH . '/default/controllers/ThanksController.php'; $request->setActionName('index'); $c = new ThanksController($request, $response, $invokeArgs); return $c->run($request, $response); }
public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { unset($this->getDi()->session->cart); $result->setAction(new Am_Paysystem_Action_Redirect(REL_ROOT_URL . "/payment/" . $this->getId() . "/instructions?id=" . $invoice->getSecureId($this->getId()))); }
protected function _addPendingInvoiceAndSend(Invoice $invoice, Am_Form $form, $vars) { if ($vars['paysys_id']) { try { $invoice->setPaysystem($vars['paysys_id'], false); } catch (Am_Exception_InputError $e) { $form->setError($e->getMessage()); return false; } } $errors = $invoice->validate(); if ($errors) { $form->setError(current($errors)); return false; } $invoice->data()->set('added-by-admin', $this->getDi()->authAdmin->getUserId()); $invoice->due_date = $vars['tm_due']; $invoice->save(); $et = Am_Mail_Template::load('invoice_pay_link', $invoice->getUser()->lang ? $invoice->getUser()->lang : null); $et->setUser($invoice->getUser()); $et->setUrl(ROOT_SURL . sprintf('/pay/%s', $invoice->getSecureId('payment-link'))); $et->setMessage($vars['message']); $et->setInvoice($invoice); $et->setInvoice_text($invoice->render()); $et->send($invoice->getUser()); return true; }
public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { $result->setAction(new Am_Paysystem_Action_Redirect(REL_ROOT_URL . "/payment/" . $this->getId() . "/confirm?id=" . $invoice->getSecureId($this->getId()))); }
function getUserCancelUrl(Invoice $invoice) { return REL_ROOT_URL . '/payment/' . $this->getId() . '/cancel?id=' . $invoice->getSecureId('STOP' . $this->getId()); }
function _setExpressAmounts(Invoice $invoice) { $this->addPostParameter('PAYMENTREQUEST_0_AMT', $invoice->first_total); $this->addPostParameter('PAYMENTREQUEST_0_CURRENCYCODE', $invoice->currency); // @todo $this->addPostParameter('PAYMENTREQUEST_0_ITEMAMT', $invoice->first_total - $invoice->first_tax); // $this->addPostParameter('PAYMENTREQUEST_0_SHIPPINGAMT', $invoice->first_shipping); $this->addPostParameter('PAYMENTREQUEST_0_TAXAMT', $invoice->first_tax); $this->addPostParameter('PAYMENTREQUEST_0_INVNUM', $invoice->getSecureId('paypal')); $this->addPostParameter('PAYMENTREQUEST_0_NOTIFYURL', $this->plugin->getPluginUrl('ipn')); $this->addPostParameter('PAYMENTREQUEST_0_PAYMENTACTION', 'Sale'); $i = 0; foreach ($invoice->getItems() as $item) { /* @var $item InvoiceItem */ $this->addPostParameter('L_PAYMENTREQUEST_0_NAME' . $i, $item->item_title); $this->addPostParameter('L_PAYMENTREQUEST_0_AMT' . $i, moneyRound(($item->first_total - $item->first_tax) / $item->qty)); // $this->addPostParameter('L_PAYMENTREQUEST_0_ITEMAMT'.$i, $item->getFirstSubtotal()); // $this->addPostParameter('L_PAYMENTREQUEST_0_NUMBER'.$i, $item->item_id); $this->addPostParameter('L_PAYMENTREQUEST_0_QTY' . $i, $item->qty); // $this->addPostParameter('L_PAYMENTREQUEST_0_TAXAMT'.$i, $item->first_tax); /// The unique non-changing identifier for the seller at the marketplace site. This ID is not displayed. //$this->addPostParameter('L_PAYMENTREQUEST_0_SELLERID'.$i, ); // PAYMENTREQUEST_n_SELLERPAYPALACCOUNTID $i++; } if ($invoice->rebill_times) { $this->addPostParameter('L_BILLINGTYPE0', 'RecurringPayments'); $this->addPostParameter('L_BILLINGAGREEMENTDESCRIPTION0', $invoice->getTerms()); } }