public static function service() { $service = new RestfulService(Director::absoluteBaseURL() . 'api/v1', 0); $service->httpHeader('Accept: application/json'); $service->httpHeader('Content-Type: application/json'); return $service; }
private function callAPI($data) { $config = $this->getConfig(); $authentication = $config['authentication']; $endpoint = $config['endpoint']; $auth = array('USER' => $authentication['username'], 'PWD' => $authentication['password'], 'SIGNATURE' => $authentication['signature']); $data = array_merge($auth, $data); $conn = new RestfulService($endpoint, 0); //REST connection that will expire immediately $conn->httpHeader('Accept: application/xml'); $conn->httpHeader('Content-Type: application/x-www-form-urlencoded'); $response = $conn->request('', 'POST', http_build_query($data)); return $response; }
public function process($data) { //parent::process($data); $authentication = self::get_authentication(); $this->postData = array(); $this->postData['USER'] = $authentication['username']; $this->postData['PWD'] = $authentication['password']; $this->postData['SIGNATURE'] = $authentication['signature']; // $this->postData['VERSION'] = self::PAYPAL_VERSION; // $this->postData['VERSION'] = '64'; $this->postData['VERSION'] = '72.0'; $this->postData['PAYMENTACTION'] = self::get_action(); // $this->postData['AMT'] = $data['Amount']; // $this->postData['CURRENCY'] = $data['Currency']; $this->postData['PAYMENTREQUEST_0_AMT'] = $data['Amount']; $this->postData['PAYMENTREQUEST_0_CURRENCYCODE'] = $data['Currency']; $this->postData['METHOD'] = 'SetExpressCheckout'; $this->postData['RETURNURL'] = $this->returnURL; $this->postData['CANCELURL'] = $this->returnURL; SS_Log::log(new Exception(print_r($this->postData, true)), SS_Log::NOTICE); $paystation = new RestfulService(self::get_url(), 0); //REST connection that will expire immediately $paystation->httpHeader('Accept: application/xml'); $paystation->httpHeader('Content-Type: application/x-www-form-urlencoded'); $response = $paystation->request('', 'POST', http_build_query($this->postData)); // $endpoint = self::get_url(); // $data = http_build_query($this->postData); // $service = new RestfulService($endpoint); // $response = $service->request(null, 'POST', $this->postData); //$response = $this->postPaymentData($this->postData); SS_Log::log(new Exception(print_r($response, true)), SS_Log::NOTICE); if ($response->getStatusCode() != '200') { return new PaymentGateway_Failure($response); } else { if ($token = $this->getToken($response)) { // If Authorization successful, redirect to PayPal to complete the payment Controller::curr()->redirect(self::get_paypal_redirect_url() . "?cmd=_express-checkout&token={$token}"); } else { // Otherwise, return failure message $errorList = $this->getErrors($response); return new PaymentGateway_Failure(null, null, $errorList); } } }
/** * Gets the overview data from new relic */ public function overview_data() { //Purge Requirements Requirements::clear(); //If we're not configured properly return an error if (!$this->getIsConfigured()) { $msg = _t('NewRelicPerformanceReport.API_APP_CONFIG_ERROR', '_New Relic API Key or Application ID is missing, check configuration'); $e = new SS_HTTPResponse_Exception($msg, 400); $e->getResponse()->addHeader('Content-Type', 'text/plain'); $e->getResponse()->addHeader('X-Status', rawurlencode($msg)); throw $e; return; } //Build the base restful service object $service = new RestfulService('https://api.newrelic.com/v2/applications/' . Convert::raw2url($this->config()->application_id) . '/metrics/data.json', $this->config()->refresh_rate); $service->httpHeader('X-Api-Key:' . Convert::raw2url($this->config()->api_key)); //Perform the request $response = $service->request('', 'POST', 'names[]=HttpDispatcher&names[]=Apdex&names[]=EndUser/Apdex&names[]=Errors/all&names[]=EndUser&period=60'); //Retrieve the body $body = $response->getBody(); if (!empty($body)) { $this->response->addHeader('Content-Type', 'application/json; charset=utf-8'); return $body; } //Data failed to load $msg = _t('NewRelicPerformanceReport.DATA_LOAD_FAIL', '_Failed to retrieve data from New Relic'); $e = new SS_HTTPResponse_Exception($msg, 400); $e->getResponse()->addHeader('Content-Type', 'text/plain'); $e->getResponse()->addHeader('X-Status', rawurlencode($msg)); throw $e; }
/** * Handles actual communication with API server. */ protected function apiCall($method, $data = array()) { $postfields = array('METHOD' => $method, 'VERSION' => $this->Config()->get("version"), 'USER' => $this->Config()->get("API_UserName"), 'PWD' => $this->Config()->get("API_Password"), 'SIGNATURE' => $this->Config()->get("API_Signature"), 'BUTTONSOURCE' => $this->Config()->get("sBNCode")); if (Director::isDev() || self::$debug) { debug::log("POST FIELDS: " . print_r($postfields, 1)); } if (Director::isDev() || self::$debug) { debug::log("ADD POINT: " . print_r($this->getApiEndpoint(), 1)); } $postfields = array_merge($postfields, $data); //Make POST request to Paypal via RESTful service $rs = new RestfulService($this->getApiEndpoint(), 0); //REST connection that will expire immediately $rs->httpHeader('Accept: application/xml'); $rs->httpHeader('Content-Type: application/x-www-form-urlencoded'); $response = $rs->request('', 'POST', http_build_query($postfields)); if (Director::isDev() || self::$debug) { debug::log(print_r($response, 1)); } return $this->deformatNVP($response->getBody()); }
function complete() { //TODO: check that request came from paystation.co.nz if (isset($_REQUEST['ec'])) { if (isset($_REQUEST['ms'])) { $payid = (int) substr($_REQUEST['ms'], strpos($_REQUEST['ms'], '-') + 1); //extract PaystationPayment ID off the end if ($payment = DataObject::get_by_id('PaystationHostedPaymentBurnbright', $payid)) { $payment->Status = $_REQUEST['ec'] == '0' ? 'Success' : 'Failure'; if ($_REQUEST['ti']) { $payment->TransactionID = $_REQUEST['ti']; } if ($_REQUEST['em']) { $payment->Message = $_REQUEST['em']; } $this->Status = 'Success'; //Quick Lookup if (self::$usequicklookup) { $paystation = new RestfulService(self::$quicklookupurl, 0); //REST connection that will expire immediately $paystation->httpHeader('Accept: application/xml'); $paystation->httpHeader('Content-Type: application/x-www-form-urlencoded'); $data = array('pi' => PaystationHostedPaymentBurnbright::get_paystation_id(), 'ms' => $_REQUEST['ms']); $paystation->setQueryString($data); $response = $paystation->request(null, 'GET'); $sxml = $response->simpleXML(); echo "<br/>"; if ($sxml && ($s = $sxml->LookupResponse)) { //check transaction ID matches if ($payment->TransactionID != (string) $s->PaystationTransactionID) { $payment->Status = "Failure"; $payment->Message .= "The transaction ID didn't match."; } //check amount matches if ($payment->Amount * 100 != (int) $s->PurchaseAmount) { $payment->Status = "Failure"; $payment->Message .= "The purchase amount was inconsistent."; } //check session ID matches if (session_id() != substr($_REQUEST['ms'], 0, strpos($_REQUEST['ms'], '-'))) { $payment->Status = "Failure"; $payment->Message .= "Session id didn't match."; } //TODO: extra - check IP address against $payment->IP?? } elseif ($sxml && ($s = $sxml->LookupStatus)) { $payment->Status = "Failure"; $payment->Message .= $s->LookupMessage; } else { //falied connection? $payment->Status = "Failure"; $payment->Message .= "Paystation quick lookup failed."; } } $payment->write(); $payment->redirectToReturnURL(); return; } else { user_error('There is no any Paystation payment which ID is #' . $payid, E_USER_ERROR); } } else { user_error('There is no any Paystation hosted payment ID specified', E_USER_ERROR); } } else { user_error('There is no any Paystation hosted payment error code specified', E_USER_ERROR); } //TODO: sawp errors for payment failures?? }