public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { $a = new Am_Paysystem_Action_Form(self::URL); $params = array('jp_item_type' => 'cart', 'jp_item_name' => $invoice->getLineDescription(), 'order_id' => $invoice->public_id, 'jp_business' => $this->getConfig('business'), 'jp_payee' => $invoice->getEmail(), 'jp_shipping' => '', 'jp_amount_1' => $invoice->currency == 'KES' ? $invoice->first_total : $this->exchange($invoice->first_total), 'jp_amount_2' => 0, 'jp_amount_5' => $invoice->currency == 'USD' ? $invoice->first_total : 0, 'jp_rurl' => $this->getPluginUrl('thanks'), 'jp_furl' => $this->getCancelUrl(), 'jp_curl' => $this->getCancelUrl()); $invoice->data()->set('jambopay-terms-KES', $params['jp_amount_1']); $invoice->data()->set('jambopay-terms-USD', $params['jp_amount_5']); $invoice->save(); foreach ($params as $k => $v) { $a->addParam($k, $v); } $result->setAction($a); }
public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { $u = $invoice->getUser(); $request = $this->createHttpRequest(); $vars = array('VPSProtocol' => '2.23', 'TxType' => 'PAYMENT', 'Vendor' => $this->getConfig('login'), 'VendorTxCode' => $invoice->public_id . '-AMEMBER', 'Amount' => number_format($invoice->first_total, 2, '.', ''), 'Currency' => $invoice->currency ? $invoice->currency : 'USD', 'Description' => $invoice->getLineDescription(), 'NotificationURL' => $this->getPluginUrl('ipn'), 'SuccessURL' => $this->getReturnUrl(), 'RedirectionURL' => $this->getReturnUrl(), 'BillingFirstnames' => $u->name_f, 'BillingSurname' => $u->name_l, 'BillingAddress1' => $u->street, 'BillingCity' => $u->city, 'BillingPostCode' => $u->zip, 'BillingCountry' => $u->country, 'DeliveryFirstnames' => $u->name_f, 'DeliverySurname' => $u->name_l, 'DeliveryAddress1' => $u->street, 'DeliveryCity' => $u->city, 'DeliveryPostCode' => $u->zip, 'DeliveryCountry' => $u->country, 'CustomerEMail' => $u->email, 'Profile' => 'NORMAL'); if ($u->country == 'US') { $vars['BillingState'] = $u->state; $vars['DeliveryState'] = $u->state; } $request->addPostParameter($vars); $request->setUrl($this->getConfig('testing') ? self::TEST_URL : self::LIVE_URL); $request->setMethod(Am_HttpRequest::METHOD_POST); $this->logRequest($request); $response = $request->send(); $this->logResponse($response); if (!$response->getBody()) { throw new Am_Exception_InputError("An error occurred while payment request"); } $res = array(); foreach (split(PHP_EOL, $response->getBody()) as $line) { list($l, $r) = explode('=', $line, 2); $res[trim($l)] = trim($r); } if ($res['Status'] == 'OK') { $invoice->data()->set('sagepay_securitykey', $res['SecurityKey']); $invoice->update(); $a = new Am_Paysystem_Action_Form($res['NextURL']); $result->setAction($a); } else { throw new Am_Exception_InputError($res['StatusDetail']); } }
public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { $req = new Am_HttpRequest(sprintf('https://gateway-japa.americanexpress.com/api/rest/version/23/merchant/%s/session', $this->getConfig('merchant')), Am_HttpRequest::METHOD_POST); $req->setAuth('merchant.' . $this->getConfig('merchant'), $this->getConfig('password')); $req->setBody(Am_Controller::getJson(array('apiOperation' => 'CREATE_PAYMENT_PAGE_SESSION', 'order' => array('id' => $invoice->public_id, 'amount' => $invoice->first_total, 'currency' => $invoice->currency), 'paymentPage' => array('cancelUrl' => $this->getCancelUrl(), 'returnUrl' => $this->getPluginUrl('thanks'))))); $this->logRequest($req); $res = $req->send(); $this->logResponse($res); if ($res->getStatus() != 201) { $result->setFailed(sprintf('Incorrect Responce Status From Paysystem [%s]', $res->getStatus())); return; } $msg = Am_Controller::decodeJson($res->getBody()); if ($msg['result'] == 'ERROR') { $result->setFailed($msg['error']['explanation']); return; } $invoice->data()->set(self::DATA_KEY, $msg['successIndicator'])->update(); $a = new Am_Paysystem_Action_Redirect(self::URL); $a->{'merchant'} = $this->getConfig('merchant'); $a->{'order.description'} = $invoice->getLineDescription(); $a->{'paymentPage.merchant.name'} = $this->getDi()->config->get('site_title'); $a->{'session.id'} = $msg['session']['id']; $this->logRequest($a); $result->setAction($a); }
public function cancelAction(Invoice $invoice, $actionName, Am_Paysystem_Result $result) { $id = $invoice->data()->get(self::PROFILE_ID); if (!$id) { throw new Am_Exception_InputError("No external id recorded for invoice [" . $invoice->public_id . "]"); } $resp = $this->apiRequest('suspendSubscription', array('profileid' => $id)); if ($resp->recurring->status == 'suspended') { echo "Order Cancelled"; } else { throw new Am_Exception_InputError("PWC: Unknown response from API"); } }
public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { $prSpeeds = array(); foreach ($invoice->getProducts() as $product) { $prSpeeds[] = ($o = $product->data()->get('bitpay_speed_risk')) ? $o : $this->getConfig('bitpay_speed_risk'); } $user = $invoice->getUser(); $post = array('price' => $invoice->first_total, 'currency' => $invoice->currency, 'posData' => array(), 'notificationURL' => $this->getPluginUrl('ipn'), 'transactionSpeed' => $this->transactionSpeed[min($prSpeeds)], 'redirectURL' => $this->getConfig('use_http', false) ? str_replace('https://', 'http://', $this->getReturnUrl()) : $this->getReturnUrl(), 'orderID' => $invoice->public_id, 'itemDesc' => $invoice->getLineDescription(), 'buyerName' => $user->getName(), 'buyerAddress1' => $user->street, 'buyerAddress2' => $user->street2, 'buyerState' => Am_Di::getInstance()->stateTable->getTitleByCode($user->country, $user->state), 'buyerZip' => $user->zip, 'buyerCountry' => Am_Di::getInstance()->countryTable->getTitleByCode($user->country), 'buyerEmail' => $user->email, 'buyerPhone' => $user->phone); $post = array_filter($post); $req = new Am_Request_Bitpay($this, Am_HttpRequest::METHOD_POST, json_encode($post), 'createInvoice'); $res = $req->getResult(); if (!isset($res['status']) || $res['status'] != 'new') { Am_Di::getInstance()->errorLogTable->log("BitPay API Error. Invoice status is not NEW: " . @$res['status'] . "."); throw new Am_Exception_InternalError(); } $invoice->data()->set(self::BITPAY_INVOICE_ID, $res['id'])->update(); $action = new Am_Paysystem_Action_Redirect($res['url']); $result->setAction($action); }
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); }
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; }
function cancelInvoice(Invoice $invoice) { $r = new Am_HttpRequest(self::URL, Am_HttpRequest::METHOD_POST); $r->addPostParameter('userkey', $this->getConfig('api_key')); $r->addPostParameter('type', self::CANCEL); $r->addPostParameter('version', '2.6'); $r->addPostParameter('transid', $invoice->data()->get(self::INITIAL_TRANSACTION_ID)); $r->addPostParameter('merchantMID', $this->getPlugin()->getConfig('mid', 1)); $tr = new Am_Paysystem_Transaction_Altcharge($this, $payment->getInvoice(), $r, $doFirst); $tr->run(new Am_Paysystem_Result()); }
function processRecurring(Invoice $invoice, $doFirst = true) { $request = new Am_HttpRequest(self::API_URL, Am_HttpRequest::METHOD_POST); $post_params = new stdclass(); $post_params->protocol = '6'; $post_params->msgtype = 'recurring'; $post_params->merchant = $this->getConfig('merchant'); $post_params->ordernumber = $invoice->public_id . "-" . sprintf("%03d", $invoice->getPaymentsCount()) . "-R"; $post_params->amount = ($doFirst ? $invoice->first_total : $invoice->second_total) * 100; $post_params->currency = $invoice->currency; $post_params->autocapture = '1'; $post_params->transaction = $invoice->data()->get(self::SUBSCRIBE); foreach ((array) $post_params as $k => $v) { $cstr .= $v; } $cstr .= $this->getConfig('secret'); $post_params->md5check = md5($cstr); $request->addPostParameter((array) $post_params); return $request; }
public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { $encoded = file_get_contents(dirname(__FILE__) . '/resource.cgn'); $decoded = $this->zapakiraj($this->simpleXOR($this->odpakiraj($encoded))); $temp = tempnam(DATA_DIR, 'bnk'); file_put_contents($temp, $decoded); $zipFile = zip_open($temp); while ($zipEntry = zip_read($zipFile)) { if (zip_entry_name($zipEntry) == $this->getConfig('terminal_id') . '.xml') { $zip_entry_exist = true; if (zip_entry_open($zipFile, $zipEntry)) { $readStream = zip_entry_read($zipEntry); $data = unpack("N*", $readStream); for ($i = 1; $i < count($data) + 1; $i++) { $data1[$i - 1] = $data[$i]; } $xorData = $this->simpleXOR($data1); $bin = null; for ($i = 0; $i < count($xorData); $i++) { $bin .= pack("N", $xorData[$i]); } $decoded = unpack("C*", $bin); $xmlString = ""; for ($i = 1; $i < count($decoded) + 1; $i++) { $xmlString .= chr($decoded[$i]); } $strData = $xmlString; zip_entry_close($zipEntry); } } } zip_close($zipFile); if (!$zip_entry_exist) { $this->getDi()->errorLogTable->log("BANKART API ERROR : terminal xml file is not found in cgn file"); throw new Am_Exception_InputError(___('Error happened during payment process. ')); } //for some reasone xml is broken in bankart cgn file $strData = preg_replace("/\\<\\/term[a-z]+\$/", '</terminal>', $strData); $terminal = new SimpleXMLElement($strData); $port = (string) $terminal->port[0]; $context = (string) $terminal->context[0]; if ($port == "443") { $url = "https://"; } else { $url = "http://"; } $url .= (string) $terminal->webaddress[0]; if (strlen($port) > 0) { $url .= ":" . $port; } if (strlen($context) > 0) { if ($context[0] != "/") { $url .= "/"; } $url .= $context; if (!$context[strlen($context) - 1] != "/") { $url .= "/"; } } else { $url .= "/"; } $url .= "servlet/PaymentInitHTTPServlet"; $vars = array('id' => (string) $terminal->id[0], 'password' => (string) $terminal->password[0], 'passwordhash' => (string) $terminal->passwordhash[0], 'action' => 4, 'amt' => $invoice->first_total, 'currency' => $this->currency_codes[$invoice->currency], 'responseURL' => $this->getPluginUrl('ipn'), 'errorURL' => $this->getRootUrl() . "/cancel", 'trackId' => $invoice->public_id, 'udf1' => $invoice->public_id); $req = new Am_HttpRequest($url, Am_HttpRequest::METHOD_POST); $req->addPostParameter($vars); $res = $req->send(); $body = $res->getBody(); if (strpos($body, 'ERROR') > 0) { $this->getDi()->errorLogTable->log("BANKART API ERROR : {$body}"); throw new Am_Exception_InputError(___('Error happened during payment process. ')); } list($payment_id, $url) = explode(':', $body, 2); $invoice->data()->set('bankart_payment_id', $payment_id)->update(); $a = new Am_Paysystem_Action_Redirect($url . '?PaymentID=' . $payment_id); $result->setAction($a); }
public function cancelInvoice(Invoice $invoice) { if (!($rbAccId = $invoice->data()->get(self::RB_ACCOUNT_ID_KEY))) { throw new Am_Exception_InputError("Subscription can not be cancelled"); } $request = new Am_HttpRequest(self::URL_RB, Am_HttpRequest::METHOD_POST); $request->addPostParameter(array('serviceVersion' => '1.0', 'operationType' => 'C', 'merchantId' => $this->getConfig('merchant_id'), 'passCode' => $this->getConfig('passcode'), 'rbAccountId' => $rbAccId)); $response = $request->send()->getBody(); $xml = simplexml_load_string($response); if ((string) $xml->code != 1) { throw new Am_Exception_InternalError("Cancel subscription[{$invoice->pk()}/{$invoice->public_id}] ERROR: " . (string) $xml->message); } $invoice->data()->set(self::RB_ACCOUNT_ID_KEY, null)->update(); return true; }
public function cancelInvoice(Invoice $invoice) { $subscriptionid = $invoice->data()->get(self::SUBSCRIPTIONID); if (!$subscriptionid) { throw new Am_Exception_InternalError('Subscriptionid is empty in invoice! Nothing to cancel. '); } $result = $this->APIRequest("subscription", "deletesubscription", array('merchantnumber' => $this->getConfig('id'), 'subscriptionid' => $subscriptionid)); $xml = $this->getResponseXML($result); if ($xml->deletesubscriptionResponse->deletesubscriptionResult != 'true') { throw new Am_Exception_InternalError("Subscription was not cancelled! Got: " . $result); } // Cancelled; return; }
function getUserCancelUrl(Invoice $invoice) { $customerUrl = ''; $SubscriptionURL = $invoice->data()->get('SubscriptionURL'); $OrderReference = $invoice->data()->get('OrderReference2'); if ($SubscriptionURL != '') { $customerUrl = $SubscriptionURL; } elseif ($OrderReference != '') { $url = sprintf("https://api.fastspring.com/company/%s/subscription/%s?user=%s&pass=%s", $this->getConfig('company'), $OrderReference, $this->getConfig('api_user'), $this->getConfig('api_pass')); $request = new Am_HttpRequest($url); $response = $request->send(); $body = $response->getBody(); if (strpos($body, "<?xml") !== false) { $xml = simplexml_load_string(); $customerUrl = $xml->customerUrl; } else { $this->logResponse($body); } } return $customerUrl; }
public function cancelAction(Invoice $invoice, $actionName, Am_Paysystem_Result $result) { // Cancelling subscription $subscriptionId = $invoice->data()->get('subscription_id'); $response = $this->_sendRequest('/subscriptions/' . $subscriptionId . '/actions/cancel'); if ($response->getStatus() !== 200) { throw new Am_Exception_InputError("An error occurred while cancellation request"); } // Cancelling mandate $mandateId = $invoice->data()->get('mandate_id'); $response = $this->_sendRequest('/mandates/' . $mandateId . '/actions/cancel'); if ($response->getStatus() !== 200) { throw new Am_Exception_InputError("An error occurred while cancellation request"); } }
public function getAdminCancelUrl(Invoice $invoice) { if ($invoice->data()->get(self::PAYPAL_PROFILE_ID) && $this->getConfig('api_username') && $this->getConfig('api_password') && $this->getConfig('api_signature')) { return parent::getAdminCancelUrl($invoice); } return 'https://' . $this->domain . '?' . http_build_query(array('cmd' => '_subscr-find', 'alias' => $this->getConfig('merchant_id')), '', '&'); }
public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result) { if (!$doFirst) { $dpsBillingId = $invoice->data()->get(self::DPS_BILLING_ID); if (!$dpsBillingId) { return $result->setFailed(array("No saved DPS_BILLING_ID for invoice")); } $transaction = new Am_Paysystem_Transaction_CreditCard_PaymentExpress_Rebill($this, $invoice, $doFirst, $dpsBillingId); $transaction->run($result); } }
public function onRebillSuccess(Invoice $invoice, EcheckRecord $echeck, Am_Paysystem_Result $result, $date) { if ($invoice->data()->get(self::FIRST_REBILL_FAILURE)) { $invoice->addToRebillDate(false, $invoice->data()->get(self::FIRST_REBILL_FAILURE)); $invoice->data()->set(self::FIRST_REBILL_FAILURE, null)->update(); } if ($this->getDi()->config->get('cc.rebill_success')) { $this->sendRebillSuccessToUser($invoice); } }
public function onRebillSuccess(Invoice $invoice, CcRecord $cc, Am_Paysystem_Result $result, $date) { if ($invoice->data()->get(self::FIRST_REBILL_FAILURE)) { $invoice->data()->set(self::FIRST_REBILL_FAILURE, null)->update(); } }
public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result) { $r = new Am_HttpRequest(self::REBILL_URL, Am_HttpRequest::METHOD_POST); $vars = array('MerchantId' => $this->getConfig('merchant_id'), 'RebillAnchor' => $invoice->data()->get(self::REBILL_ANCHOR), 'OrderId' => $invoice->public_id . '-' . $invoice->getPaymentsCount(), 'Amount' => $invoice->second_total, 'Currency' => $invoice->currency, 'ContentType' => 'text'); $vars['SecurityKey'] = $this->getRebillSecurityKey($vars); foreach ($vars as $k => $v) { $r->addPostParameter($k, $v); } $transaction = new Am_Paysystem_Transaction_PayonlineSystemRebill($this, $invoice, $r, $doFirst); $transaction->run($result); }
function locationIsValid(Invoice $invoice) { $evidence = array(); $user = $invoice->getUser(); $invoice->data()->set(self::INVOICE_IP, $invoice_ip = $this->getDi()->request->getClientIp()); $invoice->data()->set(self::USER_REGISTRATION_IP, $user->remote_addr); $invoice->data()->set(self::USER_COUNTRY, $user_country = $user->get('country')); if (!$invoice->data()->get(self::INVOICE_COUNTRY)) { $invoice->data()->set(self::INVOICE_COUNTRY, $user_country); } if ($this->getConfig('tax_location_validate_self')) { $invoice->data()->set(self::SELF_VALIDATION_COUNTRY, $evidence[] = $user->data()->get(self::SELF_VALIDATION_COUNTRY)); } try { $invoice->data()->set(self::INVOICE_IP_COUNTRY, $evidence[] = $this->getCountryLookupService()->getCountryCodeByIp($invoice_ip)); } catch (Exception $e) { $this->getDi()->errorLogTable->logException($e); } try { $invoice->data()->set(self::USER_REGISTRATION_IP_COUNTRY, $evidence[] = $this->getCountryLookupService()->getCountryCodeByIp($user->remote_addr)); } catch (Exception $e) { $this->getDi()->errorLogTable->logException($e); } if (!in_array($user_country, $evidence)) { return false; } return true; }