/** * Check if response is valid, only for advance mode * * @example data = [fp_paidto, fp_paidby, fp_store, fp_amnt, fp_batchnumber, fp_currency] * @param array $data * @return bool * @throws \Exception */ public function validateHash(array $data) { $fpHash = isset($data['fp_hash']) ? $data['fp_hash'] : null; if (empty($fpHash)) { return true; } $parameters = $this->getParameters(); $secret = isset($parameters['secret']) ? $parameters['secret'] : ''; if (empty($secret)) { throw new \Exception("Secret key is required!"); } $response = array($data['fp_paidto'], $data['fp_paidby'], $data['fp_store'], $data['fp_amnt'], $data['fp_batchnumber'], $data['fp_currency'], $secret); $hash = Security::getHash($response); if (strcmp($fpHash, $hash) !== 0) { throw new \Exception("Invalid response! Secret key is wrong!"); } return true; }
public function testCompletePurchaseAdvanceModeSuccess() { $secret = 1000; $responseParams = array('fp_paidto' => 'FP000001', 'fp_paidby' => 'FP000002', 'fp_amnt' => 1000, 'fp_fee_amnt' => 1000, 'fp_currency' => 'IDR', 'fp_batchnumber' => 'DDDADS234234', 'fp_store' => null, 'fp_timestamp' => date('Y-m-d H:i:s'), 'fp_merchant_ref' => '1311059195'); $hash = Security::getHash(array($responseParams['fp_paidto'], $responseParams['fp_paidby'], $responseParams['fp_store'], $responseParams['fp_amnt'], $responseParams['fp_batchnumber'], $responseParams['fp_currency'], $secret)); $responseParams['fp_hash'] = $hash; $request = $this->gateway->completePurchase($responseParams); $request->setSecret($secret); $response = $request->sendData($responseParams); //Response validation $this->assertTrue($response->isSuccessful()); $this->assertSame($response->getTransactionReference(), $responseParams['fp_batchnumber']); $this->assertSame($secret, $request->getSecret()); }