Esempio n. 1
0
 public function __construct($headers = null, $body = null)
 {
     $config = Payplug::getConfig();
     if (is_null($config)) {
         throw new ParametersNotSetException();
     }
     if (is_null($body)) {
         $body = file_get_contents("php://input");
     }
     if (is_null($headers)) {
         $headers = getallheaders();
     }
     $headers = array_change_key_case($headers, CASE_UPPER);
     $signature = base64_decode($headers['PAYPLUG-SIGNATURE']);
     $publicKey = openssl_pkey_get_public($config->payplugPublicKey);
     $isValid = openssl_verify($body, $signature, $publicKey, OPENSSL_ALGO_SHA1);
     if (!$isValid) {
         throw new InvalidSignatureException();
     }
     $data = json_decode($body, true);
     $this->amount = $data['amount'];
     $this->customData = $data['custom_data'];
     $this->customer = $data['customer'];
     $this->email = $data['email'];
     $this->firstName = $data['first_name'];
     $this->idTransaction = $data['id_transaction'];
     $this->lastName = $data['last_name'];
     $this->order = $data['order'];
     $this->origin = $data['origin'];
     $this->state = $data['state'];
 }
Esempio n. 2
0
 public static function generateUrl($params)
 {
     $config = Payplug::getConfig();
     $data;
     $signature;
     if (!$config) {
         throw new ParametersNotSetException();
     }
     if (!isset($params['amount'])) {
         throw new MissingRequiredParameterException("Missing required parameter: amount");
     }
     if (!isset($params['currency'])) {
         throw new MissingRequiredParameterException("Missing required parameter: currency");
     }
     if (!isset($params['ipnUrl'])) {
         throw new MissingRequiredParameterException("Missing required parameter: ipnUrl");
     }
     if (!preg_match("/^(http|https):\\/\\//i", $params['ipnUrl'])) {
         throw new MalformedURLException($params['ipnUrl'] . " doesn't starts with 'http://' or 'https://'");
     }
     if ($params['returnUrl'] != null && !preg_match("/^(http|https):\\/\\//i", $params['returnUrl'])) {
         throw new MalformedURLException($params['returnUrl'] . " doesn't starts with 'http://' or 'https://'");
     }
     $url_params = http_build_query(array("amount" => $params['amount'], "currency" => $params['currency'], "custom_data" => $params['customData'], "customer" => $params['customer'], "email" => $params['email'], "first_name" => $params['firstName'], "ipn_url" => $params['ipnUrl'], "last_name" => $params['lastName'], "order" => $params['order'], "origin" => $params['origin'] . " payplug-php" . Payplug::VERSION . " PHP" . phpversion(), "return_url" => $params['returnUrl']));
     $data = urlencode(base64_encode($url_params));
     $privateKey = openssl_pkey_get_private($config->privateKey);
     openssl_sign($url_params, $signature, $privateKey, OPENSSL_ALGO_SHA1);
     $signature = urlencode(base64_encode($signature));
     return $config->paymentBaseUrl . "?data=" . $data . "&sign=" . $signature;
 }