Esempio n. 1
0
 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);
 }
Esempio n. 2
0
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     $xml = new SimpleXMLElement('<ewaygateway></ewaygateway>');
     $xml->ewayCustomerID = $this->getConfig('customer_id');
     $xml->ewayTotalAmount = $doFirst ? $invoice->first_total * 100 : $invoice->second_total * 100;
     $xml->ewayCustomerFirstName = $cc->cc_name_f;
     $xml->ewayCustomerLastName = $cc->cc_name_l;
     $xml->ewayCustomerEmail = $invoice->getUser()->email;
     $xml->ewayCustomerAddress = $cc->cc_street;
     $xml->ewayCustomerPostcode = $cc->cc_zip;
     $xml->ewayCustomerInvoiceDescription = $invoice->getLineDescription();
     $xml->ewayCustomerInvoiceRef = $invoice->public_id;
     $xml->ewayCardHoldersName = sprintf('%s %s', $cc->cc_name_f, $cc->cc_name_l);
     $xml->ewayCardNumber = $cc->cc_number;
     $xml->ewayCardExpiryMonth = $cc->getExpire('%1$02d');
     $xml->ewayCardExpiryYear = $cc->getExpire('%2$02d');
     $xml->ewayTrxnNumber = $invoice->public_id;
     $xml->ewayOption1 = '';
     $xml->ewayOption2 = '';
     $xml->ewayOption3 = '';
     $xml->ewayCVN = $cc->getCvv();
     $request = new Am_HttpRequest($this->getGateway(), Am_HttpRequest::METHOD_POST);
     $request->setBody($xml->asXML());
     $request->setHeader('Content-type', 'text/xml');
     $tr = new Am_Paysystem_Transaction_CreditCard_Eway($this, $invoice, $request, $doFirst);
     $tr->run($result);
 }
Esempio n. 3
0
 public function validateSource()
 {
     $params = array('preapproval_id' => $this->request->get('preapproval_id'));
     $req = new Am_HttpRequest($this->plugin->getUrl() . "/preapproval/", Am_HttpRequest::METHOD_POST);
     $req->setBody(json_encode($params));
     $req->setHeader("Content-Type", "application/json");
     $req->setHeader("Authorization", "Bearer " . $this->plugin->getConfig('token'));
     $res = $req->send();
     $arr = json_decode($res->getBody(), true);
     $this->log->add(var_export($arr, true));
     if ($res->getStatus() != 200) {
         Am_Di::getInstance()->errorLogTable->log("WEPAY API ERROR : {$arr['error_code']} - {$arr['error_description']}");
         return false;
     }
     if (!empty($arr['error_description'])) {
         return false;
     }
     $this->preapproval = $arr;
     return true;
 }
Esempio n. 4
0
 function apiRequest($table, $value)
 {
     $url = self::APIURL . $this->getPlugin()->getConfig('merchant_id') . "/" . $table . "/" . $value;
     try {
         $r = new Am_HttpRequest($url, Am_HttpRequest::METHOD_POST);
         $r->setBody("<Request><Key>" . $this->getPlugin()->getConfig('key') . "</Key></Request>");
         $resp = $r->send()->getBody();
         $xml = simplexml_load_string($resp);
         if (!$xml) {
             throw new Am_Exception_Paysystem_TransactionInvalid('1SC API response is not a valid XML:' . $resp);
         }
         if ((string) $xml->attributes()->success != 'true') {
             throw new Am_Exception_Paysystem_TransactionInvalid('1SC API response is not sucessfull: ' . $resp);
         }
     } catch (Exception $e) {
         Am_Di::getInstance()->errorLogTable->logException($e);
         return null;
     }
     return $xml;
 }
Esempio n. 5
0
 function APIRequest($type = 'subscription', $function = '', $vars = array())
 {
     try {
         $client = new Am_HttpRequest(sprintf("https://ssl.ditonlinebetalingssystem.dk/remote/%s.asmx?op=%s", $type, $function), Am_HttpRequest::METHOD_POST);
         $client->setHeader('Content-type', 'text/xml');
         $client->setHeader('SOAPAction', sprintf("https://ssl.ditonlinebetalingssystem.dk/remote/%s/%s", $type, $function));
         $client->setBody($xml = $this->createXML($type, $function, $vars));
         $response = $client->send();
     } catch (Exception $e) {
         $this->getDi()->errorLogTable->logException($e);
         throw new Am_Exception_InputError("Unable to contact webservice. Got error: " . $e->getMessage());
     }
     if (!$response->getBody()) {
         throw new Am_Exception_InputError("Empty response received from API");
     }
     return $response->getBody();
 }
Esempio n. 6
0
 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());
     }
 }