Esempio n. 1
0
 /** @return  HTTP_Request2_Response */
 public function _sendRequest(Am_HttpRequest $request)
 {
     $request->addPostParameter('x_login', $this->getConfig('login'));
     $request->addPostParameter('x_tran_key', $this->getConfig('tkey'));
     $request->addPostParameter('x_Delim_Data', "True");
     $request->addPostParameter('x_Delim_Char', "|");
     $request->addPostParameter('x_Version', "3.1");
     if ($this->getConfig('testing')) {
         $request->addPostParameter("x_test_request", "TRUE");
         $request->setUrl(self::SANDBOX_URL);
     } else {
         $request->setUrl(self::LIVE_URL);
     }
     $request->setMethod(Am_HttpRequest::METHOD_POST);
     return $request;
 }
Esempio n. 2
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $user = $invoice->getUser();
     if (!$user->data()->get(self::DATA_KEY)) {
         //create user
         $req = new Am_HttpRequest($this->url(), Am_HttpRequest::METHOD_POST);
         $req->addPostParameter(array('fn' => 'eWallet_RegisterUser', 'MerchantGUID' => $this->getConfig('MerchantGUID'), 'MerchantPassword' => $this->getConfig('MerchantPassword'), 'UserName' => $user->login, 'FirstName' => $user->name_f, 'LastName' => $user->name_l, 'EmailAddress' => $user->email, 'DateOfBirth' => '1/1/1900'));
         $this->logRequest($req);
         $resp = $req->send();
         $this->logResponse($resp);
         if ($resp->getStatus() != 200) {
             $result->setFailed('Incorrect HTTP response status: ' . $resp->getStatus());
             return;
         }
         parse_str($resp->getBody(), $tmp);
         parse_str($tmp['response'], $params);
         if ($params['m_Code'] != 'NO_ERROR') {
             $result->setFailed($params['m_Text']);
             return;
         }
         $user->data()->set(self::DATA_KEY, $params['TransactionRefID'])->update();
     }
     //create invoice
     $req = new Am_HttpRequest($this->url(), Am_HttpRequest::METHOD_POST);
     $arrItems = array('Amount' => $invoice->first_total, 'CurrencyCode' => $invoice->currency, 'ItemDescription' => $invoice->getLineDescription(), 'MerchantReferenceID' => $invoice->public_id, 'UserReturnURL' => $this->getReturnUrl(), 'MustComplete' => 'false', 'IsSubscription' => 'false');
     $req->addPostParameter(array('fn' => 'eWallet_AddCheckoutItems', 'MerchantGUID' => $this->getConfig('MerchantGUID'), 'MerchantPassword' => $this->getConfig('MerchantPassword'), 'UserName' => $user->login, 'arrItems' => sprintf('[%s]', http_build_query($arrItems)), 'AutoChargeAccount' => 'false'));
     $this->logRequest($req);
     $resp = $req->send();
     $this->logResponse($resp);
     if ($resp->getStatus() != 200) {
         $result->setFailed('Incorrect HTTP response status: ' . $resp->getStatus());
         return;
     }
     parse_str($resp->getBody(), $tmp);
     parse_str($tmp['response'], $params);
     if ($params['m_Code'] != 'NO_ERROR') {
         $result->setFailed($params['m_Text']);
         return;
     }
     //login and redirect
     $req = new Am_HttpRequest($this->url(), Am_HttpRequest::METHOD_POST);
     $req->addPostParameter(array('fn' => 'eWallet_RequestUserAutoLogin', 'MerchantGUID' => $this->getConfig('MerchantGUID'), 'MerchantPassword' => $this->getConfig('MerchantPassword'), 'UserName' => $user->login));
     $this->logRequest($req);
     $resp = $req->send();
     $this->logResponse($resp);
     if ($resp->getStatus() != 200) {
         $result->setFailed('Incorrect HTTP response status: ' . $resp->getStatus());
         return;
     }
     parse_str($resp->getBody(), $tmp);
     parse_str($tmp['responset'], $params);
     if ($params['m_Code'] != 'NO_ERROR') {
         $result->setFailed($params['m_Text']);
         return;
     }
     $a = new Am_Paysystem_Action_Redirect($this->urlLogin());
     $a->secKey = $params['m_ProcessorTransactionRefNumber'];
     $result->setAction($a);
 }
Esempio n. 3
0
 public function validateSource()
 {
     $request = new Am_HttpRequest($this->getPlugin()->getConfig('testing') ? Am_Paysystem_Cashenvoy::SANDBOX_STATUS_URL : Am_Paysystem_Cashenvoy::LIVE_STATUS_URL, Am_HttpRequest::METHOD_POST);
     $request->addPostParameter(array('mertid' => $this->getPlugin()->getConfig('merchant_id'), 'transref' => $this->request->getFiltered("ce_transref"), 'respformat' => 'json'));
     $response = $request->send();
     $this->vars = json_decode($response->getBody(), true);
     $this->log->add($this->vars);
     return true;
 }
Esempio n. 4
0
 public function apiRequest($method, $vars)
 {
     $req = new Am_HttpRequest(self::API_URL . "/" . $method . ".html", Am_HttpRequest::METHOD_POST);
     $req->addPostParameter('merchantid', $this->getConfig('merchant_id'));
     $req->addPostParameter('signature', $this->getConfig('api_signature'));
     foreach ($vars as $k => $v) {
         $req->addPostParameter($k, $v);
     }
     $req->send();
     $resp = $req->getBody();
     if (!$resp) {
         throw new Am_Exception_InputError('PWC: got empty response from API server');
     }
     $xml = simplexml_load_string($resp);
     if ($xml->error) {
         throw new Am_Exception_InputError('PWC: Got error from API: ' . $xml->error->errortext);
     }
     return $xml;
 }
Esempio n. 5
0
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     if (!($trxid = $invoice->getUser()->data()->get(self::INVOICE_TRANSACTION_ID))) {
         throw new Am_Exception_Paysystem("Stored targetpay-wap trxid not found");
     }
     $request = new Am_HttpRequest(self::LIVE_URL_FOLLOWUP, Am_HttpRequest::METHOD_POST);
     $request->addPostParameter(array('trxid' => $trxid, 'service' => $this->getConfig('service'), 'amount' => $invoice->second_total * 100, 'rtlo' => $this->getConfig('rtlo'), 'description' => $invoice->getLineDescription()));
     $tr = new Am_paysystem_Transaction_TargetpayWap_Charge($this, $invoice, $request, $doFirst);
     $tr->run($result);
 }
Esempio n. 6
0
 function sendRequest($data, $method)
 {
     $request = new Am_HttpRequest('http://api.moon-ray.com/cdata.php', Am_HttpRequest::METHOD_POST);
     $request->addPostParameter(array('appid' => $this->getConfig('app_id'), 'key' => $this->getConfig('app_key'), 'return_id' => 1, 'reqType' => $method, 'data' => $data));
     $ret = $request->send();
     if ($ret->getStatus() != '200') {
         throw new Am_Exception_InternalError("Officeautopilot API Error");
     }
     $res = $ret->getBody();
     if (preg_match("|<error>(.*)</error>|", $res, $r)) {
         throw new Am_Exception_InternalError("Officeautopilot API Error - unknown response [" . $r[1] . "]");
     }
     return $res;
 }
Esempio n. 7
0
 public function changeSubscription(\User $user, array $addLists, array $deleteLists)
 {
     if (!empty($addLists)) {
         $req = new Am_HttpRequest($this->getConfig('install_url') . '/subscriber/optIn.php', Am_HttpRequest::METHOD_POST);
         foreach (array('api_action' => 'add', 'api_key' => $this->getConfig('api_key'), 'api_send_email' => $this->getConfig('api_send_email') ? 'yes' : 'no', 'email' => $user->email, 'double_optin' => $this->getConfig('double_optin', 0), 'lists' => implode(',', $addLists)) as $k => $v) {
             $req->addPostParameter($k, $v);
         }
         $req->send();
     }
     if (!empty($deleteLists)) {
         $req = new Am_HttpRequest($this->getConfig('install_url') . '/subscriber/optOut.php', Am_HttpRequest::METHOD_POST);
         foreach (array('api_action' => 'remove', 'api_key' => $this->getConfig('api_key'), 'api_send_email' => $this->getConfig('api_send_email') ? 'yes' : 'no', 'email' => $user->email, 'opt_out_type' => 1, 'lists' => implode(',', $addLists)) as $k => $v) {
             $req->addPostParameter($k, $v);
         }
         $req->send();
     }
     return true;
 }
Esempio n. 8
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $req = new Am_HttpRequest('https://' . $this->getWsHost() . '/v2/checkout', Am_HttpRequest::METHOD_POST);
     $p = array();
     $p['email'] = $this->getConfig('merchant');
     $p['token'] = $this->getConfig('token');
     $p['currency'] = strtoupper($invoice->currency);
     $p['reference'] = $invoice->public_id;
     $p['receiverEmail'] = $this->getConfig('merchant');
     $i = 1;
     foreach ($invoice->getItems() as $item) {
         $p['itemId' . $i] = $item->item_id;
         $p['itemDescription' . $i] = $item->item_title;
         $p['itemAmount' . $i] = $item->first_total;
         $p['itemQuantity' . $i] = $item->qty;
         $i++;
     }
     $p['senderEmail'] = $invoice->getUser()->email;
     $p['senderName'] = $invoice->getUser()->getName();
     $p['redirectURL'] = $this->getReturnUrl();
     $p['notificationURL'] = $this->getPluginUrl('ipn');
     $p['maxUses'] = 1;
     $p['maxAge'] = 180;
     $req->addPostParameter($p);
     $this->logRequest($req);
     $res = $req->send();
     $this->logResponse($res);
     if (!($xml = simplexml_load_string($res->getBody()))) {
         throw new Am_Exception('Incorrect XML recieved');
     }
     if ($xml->getName() == 'errors') {
         throw new Am_Exception(sprintf('%s: %s', $xml->errors[0]->code, $xml->errors[0]->message));
     }
     if ($res->getStatus() != 200) {
         throw new Am_Exception_FatalError(sprintf('Incorrect Responce Status From Paysystem [%s]', $res->getStatus()));
     }
     $code = (string) $xml->code;
     $a = new Am_Paysystem_Action_Redirect('https://' . $this->getHost() . '/v2/checkout/payment.html?code=' . $code);
     $result->setAction($a);
 }
Esempio n. 9
0
 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);
 }
Esempio n. 10
0
 function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $user = $invoice->getUser();
     $data = array('VERSION' => "0001", 'STAMP' => $invoice->public_id . '-' . $this->getDi()->time, 'AMOUNT' => $invoice->first_total * 100, 'REFERENCE' => $invoice->public_id, 'MESSAGE' => $invoice->getLineDescription(), 'LANGUAGE' => "FI", 'MERCHANT' => $this->getConfig('merchant_id'), 'RETURN' => $this->getPluginUrl('thanks'), 'CANCEL' => $this->getCancelUrl(), 'REJECT' => "", 'DELAYED' => "", 'COUNTRY' => "FIN", 'CURRENCY' => "EUR", 'DEVICE' => "10", 'CONTENT' => "1", 'TYPE' => "0", 'ALGORITHM' => "1", 'DELIVERY_DATE' => date("Ymd"), 'FIRSTNAME' => $user->name_f, 'FAMILYNAME' => $user->name_l, 'ADDRESS' => $user->street . ($user->street2 ? '; ' . $user->street2 : ''), 'POSTCODE' => $user->zip, 'POSTOFFICE' => "");
     $data['MAC'] = $this->getMac(self::$coMapOut, $data);
     $req = new Am_HttpRequest(self::URL, Am_HttpRequest::METHOD_POST);
     $req->addPostParameter($data);
     $this->logRequest($data);
     $res = $req->send();
     if ($res->getStatus() != '200') {
         throw new Am_Exception_InternalError(self::LOG_PREFIX_ERROR . "[_process()] - bad status of server response [{$res->getStatus()}]");
     }
     if (!($body = $res->getBody())) {
         throw new Am_Exception_InternalError(self::LOG_PREFIX_ERROR . "[_process()] - server return null");
     }
     $this->logResponse($body);
     if (!($xml = simplexml_load_string($body))) {
         throw new Am_Exception_InternalError(self::LOG_PREFIX_ERROR . "[_process()] - server return bad xml");
     }
     $a = new Am_Paysystem_Action_HtmlTemplate_Checkout($this->getDir(), 'payment-checkout-redirect.phtml');
     $a->xml = $xml;
     $result->setAction($a);
 }
Esempio n. 11
0
 public function cancelAction(Invoice $invoice, $actionName, Am_Paysystem_Result $result)
 {
     $this->invoice = $invoice;
     list($payment) = $invoice->getPaymentRecords();
     $params = array('key' => $this->getConfig('key'), 'ref' => $payment->receipt_id, 'uid' => $payment->user_id, 'type' => 2);
     $params['sign'] = $this->calculateSignature($params, $this->getConfig('secret'));
     $requst = new Am_HttpRequest(self::URL_TICKET, Am_HttpRequest::METHOD_POST);
     $requst->addPostParameter($params);
     $log = $this->logRequest($requst);
     $responce = $requst->send();
     $log->add($responce);
     if ($responce->getStatus() != 200) {
         $result->setFailed('Incorrect HTTP response status: ' . $responce->getStatus());
         return;
     }
     $res = Am_Controller::decodeJson($responce->getBody());
     if ($res['result'] == 1) {
         $invoice->setCancelled();
         $result->setSuccess();
         return;
     }
     $result->setFailed($res['errors']);
 }
Esempio n. 12
0
 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);
 }
Esempio n. 13
0
 function cancelAction(Invoice $invoice, $actionName, Am_Paysystem_Result $result)
 {
     $request = new Am_HttpRequest(self::CANCEL_URL, Am_HttpRequest::METHOD_POST);
     $request->addPostParameter('action', 'Cancel');
     $request->addPostParameter('email', $invoice->getEmail());
     $request->addPostParameter('mode', 'P');
     $request->addPostParameter('transaction', $this->findInitialTransactionNumber($invoice));
     $request->addPostParameter('clientaccount', $this->getConfig('account'));
     $request->addPostParameter('clientpwd', $this->getConfig('pwd'));
     $this->logRequest($request);
     $response = $request->send();
     $this->logResponse($response);
 }
Esempio n. 14
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $this->invoice = $invoice;
     $post = array('currency' => $this->invoice->currency, 'company' => $this->getConfig('company'), 'password' => $this->getConfig('password'), 'value' => $this->invoice->first_total, 'name' => $this->invoice->getLineDescription(), 'description' => $this->invoice->getLineDescription(), 'id' => $this->invoice->public_id, 'window' => $this->getConfig('window'), 'marketing' => 0, 'confirmation' => 0, 'callback_url' => $this->getPluginUrl('ipn'), 'success_url' => $this->getReturnUrl(), 'cancel_url' => $this->getCancelUrl());
     if ($this->invoice->second_total > 0) {
         if ($this->invoice->first_total > 0 && $this->invoice->first_total != $this->invoice->second_total) {
             throw new Am_Exception_InternalError('If product has no free trial first price must be the same second price');
         }
         if ($this->invoice->first_total > 0 && $this->invoice->first_period != $this->invoice->second_period) {
             throw new Am_Exception_InternalError('If product has no free trial first period must be the same second period');
         }
         $post['sub_repeat'] = $this->invoice->rebill_times == IProduct::RECURRING_REBILLS ? 0 : $this->invoice->rebill_times;
         $period = $this->parsePeriod($this->invoice->second_period);
         $post['sub_period'] = $period['period'];
         $post['sub_period_units'] = $period['period_units'];
         if (!(double) $this->invoice->first_total) {
             $post['value'] = $this->invoice->second_total;
             $period = $this->parsePeriod($this->invoice->first_period);
             $post['sub_free_period'] = $period['period'];
             $post['sub_free_period_units'] = $period['period_units'];
         }
     }
     if ($this->getConfig('debugLog')) {
         Am_Di::getInstance()->errorLogTable->log('Payforit. Request[cc]: ' . json_encode($post));
     }
     $req = new Am_HttpRequest(self::URL, Am_HttpRequest::METHOD_POST);
     $req->addPostParameter($post);
     $res = $req->send();
     if ($res->getStatus() != '200') {
         throw new Am_Exception_InternalError("Payforit API Error: bad status of server response [{$res->getStatus()}]");
     }
     if (!$res->getBody()) {
         throw new Am_Exception_InternalError("Payforit API Error: server return null");
     }
     $this->logResponse($res->getBody());
     if ($this->getConfig('debugLog')) {
         Am_Di::getInstance()->errorLogTable->log('Payforit. Response[cc]: ' . $res->getBody());
     }
     $response = explode('|', $res->getBody());
     if ($response[0] != 'OK') {
         throw new Am_Exception_InternalError("Payforit API Error: {$response[1]}");
     }
     $this->invoice->data()->set(self::TRANSACTION_ID, $response[1])->update();
     if (!$this->getConfig('is_frame')) {
         header('Location: ' . $response[2]);
         return;
     }
     $a = new Am_Paysystem_Action_HtmlTemplate_Payforit($this->getDir(), 'payment-payforit-iframe.phtml');
     $a->src = $response[2];
     $result->setAction($a);
 }
Esempio n. 15
0
 public function validate($id)
 {
     if (!$id) {
         return;
     }
     //skip validation in case of VAT was not supplied
     $plugins = Am_Di::getInstance()->plugins_tax->getAllEnabled();
     $me = is_array($plugins) ? $plugins[0]->getConfig('my_id') : "";
     if (!$me) {
         return $this->___('VAT Settings are incorrect - no Vat Id configured');
     }
     // check if response is cached
     $cacheKey = 'vat_check_' . preg_replace('/[^A-Z0-9a-z_]/', '_', $me) . '_' . preg_replace('/[^A-Z0-9a-z_]/', '_', $id);
     if (($ret = Am_Di::getInstance()->cache->load($cacheKey)) !== false) {
         return $ret === 1 ? null : $this->___('Invalid VAT Id, please try again');
     }
     if (!strlen($id)) {
         return $this->___('Invalid VAT Id, please try again');
     }
     $req = new Am_HttpRequest('http://ec.europa.eu/taxation_customs/vies/vatResponse.html', Am_HttpRequest::METHOD_POST);
     $req->addPostParameter('action', 'check')->addPostParameter('check', 'Verify')->addPostParameter('memberStateCode', strtoupper(substr($id, 0, 2)))->addPostParameter('number', substr($id, 2))->addPostParameter('requesterMemberStateCode', '')->addPostParameter('traderName', '')->addPostParameter('traderCompanyType', '')->addPostParameter('traderStreet', '')->addPostParameter('traderPostalCode', '')->addPostParameter('traderCity', '')->addPostParameter('requesterNumber', '');
     try {
         $resp = $req->send();
         $ok = preg_match('/Yes[,\\s]+valid\\s+VAT\\s+number/i', $resp->getBody());
         Am_Di::getInstance()->cache->save($ok ? 1 : 0, $cacheKey);
         if (!$ok) {
             return $this->___('Invalid VAT Id, please try again');
         }
     } catch (Exception $e) {
         Am_Di::getInstance()->errorLogTable->log($e);
         return $this->___("Cannot validate VAT Id, please try again");
     }
 }
Esempio n. 16
0
 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;
 }
Esempio n. 17
0
 public function validateDdi($vars, $invoice, &$address)
 {
     $user = $invoice->getUser();
     $request = new Am_HttpRequest(Am_Paysystem_SmartDebit::API_ENDPOINT . '/ddi/adhoc/validate', Am_HttpRequest::METHOD_POST);
     $request->setAuth($this->plugin->getConfig('login'), $this->plugin->getConfig('passwd'));
     $params = array('adhoc_ddi[reference_number]' => Am_Paysystem_SmartDebit::REF_PREFIX . $invoice->public_id, 'adhoc_ddi[first_name]' => $vars['name_f'], 'adhoc_ddi[last_name]' => $vars['name_l'], 'adhoc_ddi[address_1]' => $vars['street'], 'adhoc_ddi[town]' => $vars['city'], 'adhoc_ddi[postcode]' => $vars['zip'], 'adhoc_ddi[country]' => $vars['country'], 'adhoc_ddi[account_name]' => $vars['account_name'], 'adhoc_ddi[sort_code]' => $vars['sort_code'], 'adhoc_ddi[account_number]' => $vars['account_number'], 'adhoc_ddi[service_user][pslid]' => $this->plugin->getConfig('pslid'), 'adhoc_ddi[payer_reference]' => sprintf('U%07d', $user->pk()), 'adhoc_ddi[title]' => $invoice->getLineDescription(), 'adhoc_ddi[email_address]' => $user->email);
     $request->addPostParameter($params);
     $response = $request->send();
     $r = simplexml_load_string($response->getBody());
     if (!$r) {
         return array('Incorrect Response from Smart Debit');
     }
     if ($response->getStatus() != 200) {
         $err = array();
         foreach ($r->error as $e) {
             $err[] = (string) $e;
         }
         return $err;
     }
     foreach ($r->success as $s) {
     }
     foreach ($s->attributes() as $k => $v) {
         $address[$k] = (string) $v;
     }
     return;
 }
Esempio n. 18
0
 function getOrder($session_id)
 {
     $ts = time();
     $sig = md5($this->plugin->getConfig('pos_id') . $session_id . $ts . $this->plugin->getConfig('key1'));
     $r = new Am_HttpRequest('https://' . self::SERVER . self::SERVER_SCRIPT, 'POST');
     $r->addPostParameter(array('pos_id' => $this->plugin->getConfig('pos_id'), 'session_id' => $session_id, 'ts' => $ts, 'sig' => $sig));
     $response = $r->send()->getBody();
     $res = new SimpleXMLElement($response);
     if ($res->status != 'OK') {
         throw new Am_Exception_Paysystem_TransactionInvalid("BAD RESPONSE STATUS!");
     }
     if ($res->trans->pos_id != $this->plugin->getConfig('pos_id')) {
         throw new Am_Exception_Paysystem_TransactionInvalid("INCORECT POS NUMBER!");
     }
     $sig = md5($res->trans->pos_id . $res->trans->session_id . $res->trans->order_id . $res->trans->status . $res->trans->amount . $res->trans->desc . $res->trans->ts . $this->plugin->getConfig('key2'));
     if ($res->trans->sig != $sig) {
         throw new Am_Exception_Paysystem_TransactionInvalid("INCORECT SIGNATURE!");
     }
     $this->transaction = $res->trans;
     /* Status:
      *       1: nowa
      *       2: anulowana
      *       3: odrzucona
      *       4: rozpoczęta
      *       5: oczekuje na odbiór
      *       6: autoryzacja odmowna
      *       7: płatność odrzucona
      *       99: płatność odebrana - zakończona
      *       888: błędny status
      */
     return true;
 }
Esempio n. 19
0
 function loadUpgradesList($requireAuth = false)
 {
     $req = new Am_HttpRequest('http://www.amember.com/check-upgrades.php', Am_HttpRequest::METHOD_POST);
     $req->setConfig('connect_timeout', 5);
     if (@$_REQUEST['beta'] > 0 || defined('AM_BETA') && AM_BETA) {
         $req->addPostParameter('beta', 1);
     }
     $req->setConfig('timeout', 15);
     $req->addPostParameter('am-version', AM_VERSION);
     foreach ($this->getDi()->plugins as $type => $pm) {
         foreach ($pm->getEnabled() as $v) {
             $req->addPostParameter('plugins[' . $type . '][' . $v . ']', $pm->loadGet($v)->getVersion());
         }
     }
     foreach ($this->getDi()->config->get('lang.enabled', array()) as $l) {
         $req->addPostParameter('lang[]', $l);
     }
     $req->addPostParameter('php-version', PHP_VERSION);
     $req->addPostParameter('mysql-version', $this->getDi()->db->selectCell("SELECT VERSION()"));
     $req->addPostParameter('root-url', ROOT_URL);
     $req->addPostParameter('root-surl', ROOT_SURL);
     $req->addPostParameter('license', $this->getConfig('license'));
     $token = $this->getDi()->store->get('amember-site-auth-token');
     if (!$requireAuth) {
         $token = 'TRIAL';
     } elseif (!$token) {
         $this->_redirect('admin-upgrade/get-token');
     }
     $req->addPostParameter('token', $token);
     //
     try {
         $response = $req->send();
         if ($response->getStatus() == 401) {
             $this->_redirect('admin-upgrade/get-token');
         }
     } catch (HTTP_Request2_Exception $e) {
         $this->view->title = ___('Update Error');
         $this->view->content = ___('Could not fetch upgrades list from remote server. %sTry again%', '<a href="admin-upgrade">', '</a>');
         $this->view->display('admin/layout.phtml');
         return false;
     }
     if ($response->getStatus() != '200') {
         throw new Am_Exception_InternalError(___("Could not fetch upgrades list. Connection error [%s]", $response->getReasonPhrase()));
     }
     $xml = new SimpleXMLElement($response->getBody());
     $ret = array();
     foreach ($xml->item as $u) {
         $el = new stdclass();
         foreach ($u->attributes() as $k => $v) {
             $el->{$k} = (string) $v;
         }
         $el->text = (string) $u;
         $el->text = strip_tags($el->text, '<li><ul><b><i><p><hr><br>');
         $ret[] = $el;
     }
     return $ret;
 }
Esempio n. 20
0
 function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount)
 {
     $request = new Am_HttpRequest(self::API_URL, Am_HttpRequest::METHOD_POST);
     $post_params = new stdclass();
     $post_params->protocol = '6';
     $post_params->msgtype = 'refund';
     $post_params->merchant = $this->getConfig('merchant');
     $post_params->amount = intval($amount * 100);
     $post_params->transaction = $payment->receipt_id;
     foreach ((array) $post_params as $k => $v) {
         $cstr .= $v;
     }
     $cstr .= $this->getConfig('secret');
     $post_params->md5check = md5($cstr);
     $request->addPostParameter((array) $post_params);
     $response = $request->send();
     $parsedResponse = simplexml_load_string($response->getBody());
     if ((string) $parsedResponse->qpstat != '000') {
         $result->setFailed("Payment failed: Description - " . $this->getErrorMessage((string) $parsedResponse->qpstat) . " QuickPay message - " . $parsedResponse->qpstatmsg);
     } else {
         $trans = new Am_Paysystem_Transaction_Manual($this);
         $trans->setAmount($amount);
         $trans->setReceiptId($payment->receipt_id . '-quickpay-refund');
         $result->setSuccess($trans);
     }
 }
Esempio n. 21
0
 function resendPostback()
 {
     if ($this->plugin->getConfig('resend_postback')) {
         $urls = $this->plugin->getConfig('resend_postback_urls');
         $urls = explode("\n", $urls);
         $urls = array_filter(array_map('trim', $urls));
         foreach ($urls as $url) {
             try {
                 $tm = microtime(true);
                 $this->log->add("Resending postback to [{$url}]");
                 if ($url == $this->plugin->getPluginUrl('ipn')) {
                     throw new Am_Exception_Configuration("DO NOT CONFIGURE RESENDING IPN TO ITSELF!");
                 }
                 $req = new Am_HttpRequest($url);
                 $req->setConfig('connect_timeout', 1000);
                 $req->setConfig('timeout', 2000);
                 $method = strtoupper($this->request->getMethod());
                 $req->setMethod($method);
                 if ($method == 'POST') {
                     foreach ($this->request->getPost() as $k => $v) {
                         $req->addPostParameter($k, $v);
                     }
                 } else {
                     $arr = $this->request->getQuery();
                     $req->setUrl($req->getUrl() . '?' . http_build_query($arr));
                 }
                 $req->send();
                 $tm = sprintf('%.3f', microtime(true) - $tm);
                 $this->log->add("Postback resent succesfully ({$tm} sec)");
             } catch (Exception $e) {
                 $tm = sprintf('%.3f', microtime(true) - $tm);
                 $this->log->add("Cannot resend postback ({$tm} sec)");
                 $this->log->add($e);
             }
         }
     }
 }
Esempio n. 22
0
 public function validateSource()
 {
     $token = $this->request->getParam('token');
     $request = new Am_HttpRequest($this->getIPN2HandlerURL(), Am_HttpRequest::METHOD_POST);
     $request->addPostParameter('token', $token);
     $response = $request->send();
     $body = $response->getBody();
     if ($body == self::INVALID_TOKEN) {
         throw new Am_Exception_Paysystem_TransactionInvalid(sprintf("Invalid Token [%s] passed.", $token));
     }
     parse_str(urldecode($body), $this->ipnData);
     $this->log->add($this->ipnData);
     return true;
 }
 function upgradeFlowPlayerKey()
 {
     if (version_compare($this->db_version, '4.2.16') < 0) {
         echo "Update Flowplayer License Key...";
         if (ob_get_level()) {
             ob_end_flush();
         }
         $request = new Am_HttpRequest('https://www.amember.com/fplicense.php', Am_HttpRequest::METHOD_POST);
         $request->addPostParameter('root_url', $this->getDi()->config->get('root_url'));
         try {
             $response = $request->send();
         } catch (Exception $e) {
             echo "request failed " . $e->getMessage() . "\n<br />";
             return;
         }
         if ($response->getStatus() == 200) {
             $body = $response->getBody();
             $res = Am_Controller::decodeJson($body);
             if ($res['status'] == 'OK' && $res['license']) {
                 Am_Config::saveValue('flowplayer_license', $res['license']);
             }
         }
         echo "Done<br>\n";
     }
 }
Esempio n. 24
0
 /**
  * Fetch updated license from aMember Pro website
  */
 function updateLicense()
 {
     if (!$this->di->config->get('license')) {
         return;
     }
     // empty license. trial?
     if ($this->di->store->get('app-update-license-checked')) {
         return;
     }
     try {
         $req = new Am_HttpRequest('http://update.amember.com/license.php');
         $req->setConfig('connect_timeout', 2);
         $req->setMethod(Am_HttpRequest::METHOD_POST);
         $req->addPostParameter('license', $this->di->config->get('license'));
         $req->addPostParameter('root_url', $this->di->config->get('root_url'));
         $req->addPostParameter('root_surl', $this->di->config->get('root_surl'));
         $req->addPostParameter('version', AM_VERSION);
         $this->di->store->set('app-update-license-checked', 1, '+12 hours');
         $response = $req->send();
         if ($response->getStatus() == '200') {
             $newLicense = $response->getBody();
             if ($newLicense) {
                 if (preg_match('/^L[A-Za-z0-9\\/=+\\n]+X$/', $newLicense)) {
                     Am_Config::saveValue('license', $newLicense);
                 } else {
                     throw new Exception("Wrong License Key Received: [" . $newLicense . "]");
                 }
             }
         }
     } catch (Exception $e) {
         if (APPLICATION_ENV != 'production') {
             throw $e;
         }
     }
 }
Esempio n. 25
0
 public function __construct(Am_Paysystem_Abstract $plugin, Invoice $invoice, $charge_id, $amount = null)
 {
     $this->charge_id = $charge_id;
     $this->amount = $amount > 0 ? $amount : null;
     $request = new Am_HttpRequest('https://api.stripe.com/v1/charges/' . $this->charge_id . '/refund', 'POST');
     $request->setAuth($plugin->getConfig('secret_key'), '');
     if ($this->amount > 0) {
         $request->addPostParameter('amount', sprintf('%.2f', $this->amount) * 100);
     }
     parent::__construct($plugin, $invoice, $request, true);
 }
Esempio n. 26
0
 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());
 }
Esempio n. 27
0
 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);
 }
Esempio n. 28
0
 protected function _request($function, $method, $params = null)
 {
     $this->_request->setUrl(self::API_URL . '/' . $function);
     $nonce = sprintf('%0.0f', round(microtime(true) * 1000000));
     $data = $nonce . self::API_URL . '/' . $function . http_build_query($params);
     $this->_request->setHeader(array('ACCESS_KEY' => $this->_key, 'ACCESS_SIGNATURE' => hash_hmac('sha256', $data, $this->_secret), 'ACCESS_NONCE' => $nonce));
     $this->_request->setMethod($method);
     if (!empty($params)) {
         $this->_request->addPostParameter($params);
     }
     $resp = $this->_request->send();
     if ($resp->getStatus() != 200) {
         throw new Am_Exception_InternalError('CoinBase: Status for API request was not 200. Got: ' . $resp->getStatus());
     }
     $data = json_decode($resp->getBody());
     if (is_null($data)) {
         throw new Am_Exception_InternalError('CoinBase: Unable to decode response. Got: ' . $resp);
     }
     if (!@$data->success) {
         throw new Am_Exception_InternalError('CoinBase: Not successfull response.Got: ' . print_r($data, true));
     }
     return $data;
 }
Esempio n. 29
0
 public function __construct(Am_Paysystem_Abstract $plugin, Invoice $invoice, $transactionId, $amount = null)
 {
     $this->transactionId = $transactionId;
     $this->amount = $amount > 0 ? $amount : null;
     $request = new Am_HttpRequest(Am_Paysystem_Paymill::API_ENDPOINT . 'refunds/' . $transactionId, 'POST');
     $request->setAuth($plugin->getConfig('private_key'), '');
     if ($this->amount > 0) {
         $request->addPostParameter('amount', sprintf('%.02f', $amount) * 100)->addPostParameter('description', 'Refund from aMember script. Username: '******', invoice: ' . $invoice->public_id);
     }
     parent::__construct($plugin, $invoice, $request, true);
 }
Esempio n. 30
0
 function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount)
 {
     $request = new Am_HttpRequest("https://" . $this->getConfig('login') . ":" . $this->getConfig('password') . "@payment.architrade.com/cgi-adm/refund.cgi");
     $invoice = $payment->getInvoice();
     $currency = $this->getCurrencyCode($invoice);
     $post_params = new stdclass();
     $post_params->merchant = $this->getConfig('merchant');
     $post_params->amount = $amount * 100;
     $count = $this->getDi()->db->selectCol("SELECT COUNT(*) FROM ?_invoice_payment\n                WHERE invoice_id=?d AND dattm < ?\n                ", $payment->invoice_id, $payment->dattm);
     $post_params->orderId = $invoice->public_id . "-" . sprintf("%03d", array_shift($count));
     $post_params->transact = $invoice->data()->get(self::TICKET);
     $post_params->textreply = 'true';
     $post_params->currency = $currency;
     $post_params->md5key = md5($s2 = $this->getConfig('key2') . md5($s1 = $this->getConfig('key1') . "merchant=" . $this->getConfig('merchant') . "&orderid=" . $invoice->public_id . "&transact=" . $invoice->data()->get(self::TICKET) . "&amount=" . $amount));
     $request->addPostParameter((array) $post_params);
     $response = $request->send();
     $response = $this->parseResponse($response->getBody());
     if ($response['result'] === 0) {
         $trans = new Am_Paysystem_Transaction_Manual($this);
         $trans->setAmount($amount);
         $trans->setReceiptId($payment->receipt_id . '-dibs-refund');
         $result->setSuccess($trans);
     } else {
         $result->setFailed(array('Error Processing Refund!'));
     }
 }