About payten [NESTPAY]payment integration to Laravel 10 project
I get an error when integrating the payten(nestpay) payment infrastructure into my Laravel 10 project. I am using the 3D PAY HOSTING model.
Receiving payment in normal php code works smoothly. (I also added the document codes here.) I created a sample structure in Laravel. 3d payment returns 405 when redirecting the post. ssl gives an error that I run on my installed website.
The example I created in laravel 10 project.
routes/web.php code
Route::get('/payment', [PaymentController::class, 'showPaymentForm'])->name('payment.form'); Route::post('/payment/process', [PaymentController::class, 'processPayment'])->name('payment.process'); Route::post('/payment/response', [PaymentController::class, 'responsepayment'])->name('payment.response');
App\Http\Controllers\PaymentController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Support\Facades\Http;
class PaymentController extends Controller { public function showPaymentForm() { return view('request'); } public function responsepayment() { return view('response'); }
public function processPayment(Request $request)
{
// post data create hash
$postParams = $request->all();
$hashStr = $this->makeHashString($postParams);
$calculatedHashValue = hash('sha512', $hashStr);
$hash = base64_encode(pack('H*', $calculatedHashValue));
$postParams['HASH'] = $hash;
$response = Http::post('<poslink>/fim/est3Dgate', $postParams);
if ($response->successful()) {
// 3D safe page redirect
return redirect()->away('<poslink>/fim/est3Dgate');
} else {
return redirect()->route('payment.form')->with('error', 'Payment Fail.');
}
}
private function makeHashString($postParams)
{
$hashStr = '';
foreach ($postParams as $key => $value) {
if ($key !== 'HASH') {
$hashStr .= $value . '|';
}
}
$storeKey = "TEST1234";
$escapedStoreKey = str_replace("|", "\|", str_replace("\", "\\", $storeKey));
$hashStr .= $escapedStoreKey;
return $hashStr;
}
}
<title>3D PAY HOSTING</title>
<meta http-equiv="Content-Language" content="tr">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="now">
<form method="post" action="{{route('payment.process')}}">
@csrf
<table>
<tr>
<td align="center" colspan="2"><input type="submit"
value="Complete Payment" /></td>
</tr>
</table>
<input type="hidden" name="clientid" value="<?php echo $orgClientId ?>">
<input type="hidden" name="amount" value="<?php echo $orgAmount ?>">
<input type="hidden" name="okurl" value="<?php echo $orgOkUrl ?>">
<input type="hidden" name="failUrl" value="<?php echo $orgFailUrl ?>">
<input type="hidden" name="TranType" value="<?php echo $orgTransactionType ?>">
<input type="hidden" name="Instalment" value="<?php echo $orgInstallment ?>">
<input type="hidden" name="callbackUrl" value="<?php echo $orgCallbackUrl ?>">
<input type="hidden" name="currency" value="<?php echo $orgCurrency ?>">
<input type="hidden" name="rnd" value="<?php echo $orgRnd ?>">
<input type="hidden" name="storetype" value="3D_PAY_HOSTING">
<input type="hidden" name="hashAlgorithm" value="ver3">
<input type="hidden" name="lang" value="tr">
<input type="hidden" name="oid" value="10000">
<input type="hidden" name="BillToName" value="name">
<input type="hidden" name="BillToCompany" value="billToCompany">
<input type="hidden" name="refreshtime" value="5">
<input type="hidden" name="ItemNumber1" value="TEST">
<input type="hidden" name="ProductCode1" value="0001">
<input type="hidden" name="Qty1" value="1">
<input type="hidden" name="Desc1" value="item desc">
<input type="hidden" name="Id1" value="1">
<input type="hidden" name="Price1" value="1">
<input type="hidden" name="Total1" value="2">
<input type="hidden" name="pan" value="0000000000000000">
<input type="hidden" name="Ecom_Payment_Card_ExpDate_Year" value="28" >
<input type="hidden" name="Ecom_Payment_Card_ExpDate_Month" value="12">
</form>
response.blade.php
natcasesort($postParams);
$hashval = "";
foreach ($postParams as $param){
$paramValue = $_POST[$param];
$escapedParamValue = str_replace("|", "\|", str_replace("\", "\\", $paramValue));
$lowerParam = strtolower($param);
if($lowerParam != "hash" && $lowerParam != "encoding" ) {
$hashval = $hashval . $escapedParamValue . "|";
}
}
$storeKey = "TEST1234";
$escapedStoreKey = str_replace("|", "\|", str_replace("\", "\\", $storeKey));
$hashval = $hashval . $escapedStoreKey;
$calculatedHashValue = hash('sha512', $hashval);
$actualHash = base64_encode (pack('H*',$calculatedHashValue));
$retrievedHash = $_POST["HASH"];
if($retrievedHash == $actualHash ) {
echo "<h4>HASH is successfull</h4>" . " <br />\r\n";
}else {
echo "<h4>Security Alert. The digital signature is not valid.</h4>" . " <br />\r\n";
}
?>
Please or to participate in this conversation.