function authorizeFromEnv() { $apiKey = getenv('PAGARME_API_KEY'); if (!$apiKey) { $apiKey = "ak_test_Rw4JR98FmYST2ngEHtMvVf5QJW7Eoo"; } PagarMe::setApiKey($apiKey); }
public function run() { if (!parent::getApiKey()) { throw new PagarMe_Exception("You need to configure API key before performing requests."); } $this->parameters = array_merge($this->parameters, array("api_key" => parent::getApiKey())); // var_dump($this->parameters); // $this->headers = (PagarMe::live) ? array("X-Live" => 1) : array(); $client = new RestClient(array("method" => $this->method, "url" => $this->full_api_url($this->path), "headers" => $this->headers, "parameters" => $this->parameters)); $response = $client->run(); $decode = json_decode($response["body"], true); if ($decode === NULL) { throw new Exception("Failed to decode json from response.\n\n Response: " . $response); } else { if ($response["code"] == 200) { return $decode; } else { throw PagarMe_Exception::buildWithFullMessage($decode); } } }
public function testFingerprint() { $this->assertTrue(PagarMe::validateFingerprint('13', sha1('13' . '#' . PagarMe::getApiKey()))); }
public static function setApiKey($api_key) { self::$api_key = $api_key; }
<?php require("Pagarme.php"); Pagarme::setApiKey("ak_test_VI0RjtmUyIqfXUUYdLHGDOCEUHoUtk"); $transaction = PagarMe_Transaction::findById("176698"); $POST['id'] = $transaction->id; $POST['fingerprint'] = $transaction->card->fingerprint; print_r($POST); echo'<br><br><br><br>'; if(PagarMe::validateFingerprint($POST['id'], $POST['fingerprint'])) { echo 'valida'; }else{ echo 'false'; } ?>
if (empty($_REQUEST['email'])) { $error['email'] = 'Campo E-Mail obrigatório'; } else { $field['email'] = $_REQUEST['email']; } if (count($field)) { $session->set('field', $field); } if (count($error)) { $session->set('error', $error); header('location: /../../admin/users/create.php'); } else { // Gravação dos dados do form header('location: /../../admin/users/create.php'); } break; case 'payment': $token = $_REQUEST['token']; \PagarMe::setApiKey("ak_test_gxdZQnY40daggFTyF2UA6dA6HgpyBR"); $transaction = \PagarMe_Transaction::findById("{$token}"); $transaction->capture(75000); var_dump($transaction); break; default: echo $_REQUEST['acao']; die('default'); break; } } else { die('Request Vazio'); }
public function testFingerprint() { $expectedResult = "sha1=7820fcb6d03ec8f721c14596654d24623af9e7de"; $this->assertTrue(PagarMe::validateRequestSignature('{"sample":"payload","value":true}', $expectedResult)); $expectedResult = "sha1=hash_errado"; $this->assertFalse(PagarMe::validateRequestSignature('{"sample":"payload","value":true}', $expectedResult)); }