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 _getCountry($ip) { $req = new Am_HttpRequest(sprintf(self::URL, $ip), Am_HttpRequest::METHOD_GET); $req->setAuth($this->getAccountId(), $this->getAccountLicense()); try { $response = $req->send(); } catch (Exception $e) { throw new Am_Exception_InternalError("MaxMind GeoLocation service: Unable to contact server (got: " . $e->getMessage() . " )"); } $resp = json_decode($response->getBody()); if ($response->getStatus() !== 200) { throw new Am_Exception_InternalError("MaxMind GeoLocation service: Got an error from API server (got: " . $resp->error . " )"); } if (!empty($resp->error)) { return null; } return (string) $resp->country->iso_code; }
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); }
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); }
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; }
protected function _sendMail() { $request = new Am_HttpRequest(self::API_ENDPOINT . $this->_client_id, Am_HttpRequest::METHOD_POST); $request->setAuth($this->_api_key, 'none'); $request->setHeader('Content-type: application/json; charset=utf-8'); $params = array('TrackOpens' => true, 'TrackClicks' => true, 'InlineCSS' => true); $part = new Zend_Mail_Part(array('raw' => $this->header . Zend_Mime::LINEEND . $this->body)); $this->_extractHeaderToParams($part, 'to', $params); $this->_extractHeaderToParams($part, 'cc', $params); $this->_extractHeaderToParams($part, 'bcc', $params); $this->_extractHeaderToParams($part, 'from', $params, false); $this->_extractHeaderToParams($part, 'reply-to', $params, false); $subject = $part->getHeader('subject'); if (strpos($subject, '=?') === 0) { $subject = mb_decode_mimeheader($subject); } $params['subject'] = $subject; $params['Group'] = $subject; $canHasAttacments = false; //message list($type) = explode(";", $part->getHeader('content-type')); if ($type == 'multipart/alternative') { $msgPart = $part->getPart(2); } else { $msgPart = $part->isMultipart() ? $part->getPart(1) : $part; if ($msgPart->isMultipart()) { $msgPart = $msgPart->getPart(2); //html part } $canHasAttacments = true; } list($type) = explode(";", $msgPart->getHeader('content-type')); $encoding = $msgPart->getHeader('content-transfer-encoding'); $content = $msgPart->getContent(); if ($encoding && $encoding == 'quoted-printable') { $content = quoted_printable_decode($content); } else { $content = base64_decode($content); } switch ($type) { case 'text/plain': $params['text'] = $content; break; case 'text/html': $params['html'] = $content; break; default: throw new Zend_Mail_Transport_Exception("SendGrid API: unknown content-type: " . $type); } //attachments $handlers = array(); if ($canHasAttacments) { if ($part->isMultipart()) { $params['Attachments'] = array(); for ($i = 2; $i <= $part->countParts(); $i++) { $attPart = $part->getPart($i); $encoding = $attPart->getHeader('content-transfer-encoding'); $disposition = $attPart->getHeader('content-disposition'); preg_match('/filename="(.*)"/', $disposition, $m); $filename = $m[1]; $content = $attPart->getContent(); if ($encoding && $encoding == 'quoted-printable') { $content = quoted_printable_decode($content); $content = base64_encode($content); } $params['Attachments'][] = array('Name' => $filename, 'Type' => $attPart->{'content-type'}, 'Content' => $content); } } } $request->setBody(json_encode($params)); $response = $request->send(); if (!($body = json_decode($response->getBody(), true)) || !isset($body[0]['Status']) || $body[0]['Status'] != 'Accepted') { throw new Zend_Mail_Transport_Exception("CampaignMonitor API: unexpected response: " . $response->getBody()); } }