Skip to content

Commit

Permalink
add redirection page
Browse files Browse the repository at this point in the history
  • Loading branch information
khanzadimahdi committed Mar 6, 2019
1 parent b995318 commit 745f5a7
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 23 deletions.
60 changes: 60 additions & 0 deletions config/payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Driver
|--------------------------------------------------------------------------
|
| This value determines which of the following gateway to use.
| You can switch to a different driver at runtime.
|
*/
'default' => 'zarinpal',

/*
|--------------------------------------------------------------------------
| List of Drivers
|--------------------------------------------------------------------------
|
| These are the list of drivers to use for this package.
| You can change the name. Then you'll have to change
| it in the map array too.
|
*/
'drivers' => [
'zarinpal' => [ // set urls to https://sandbox.zarinpal.com/pg/rest/WebGate/ for using sandbox
'apiPurchaseUrl' => 'https://www.zarinpal.com/pg/rest/WebGate/PaymentRequest.json',
'apiPaymentUrl' => 'https://www.zarinpal.com/pg/StartPay/',
'apiVerificationUrl' => 'https://www.zarinpal.com/pg/rest/WebGate/PaymentVerification.json',
'merchantId' => '',
'callbackUrl' => 'http://yoursite.com/path/to',
'description' => 'payment in '.config('app.name'),
],
'irankish' => [
'apiPurchaseUrl' => 'https://ikc.shaparak.ir/XToken/Tokens.xml',
'apiPaymentUrl' => 'https://ikc.shaparak.ir/TPayment/Payment/index/',
'apiVerificationUrl' => 'https://ikc.shaparak.ir/XVerify/Verify.xml',
'merchantId' => '',
'sha1Key' => '',
'callbackUrl' => 'http://yoursite.com/path/to',
'description' => 'payment in '.config('app.name'),
],
],

/*
|--------------------------------------------------------------------------
| Class Maps
|--------------------------------------------------------------------------
|
| This is the array of Classes that maps to Drivers above.
| You can create your own driver if you like and add the
| config in the drivers array and the class to use for
| here with the same name. You will have to extend
| Shetabit\Payment\Abstracts\Driver in your driver.
|
*/
'map' => [
'zarinpal' => \Shetabit\Payment\Drivers\Zarinpal::class,
'irankish' => \Shetabit\Payment\Drivers\Irankish::class,
]
];
102 changes: 102 additions & 0 deletions resources/views/redirectForm.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Forwarding to secure payment provider</title>
<style>
.text-center {
text-align: center;
}
.mt-2 {
margin-top: 2em;
}
.spinner {
margin: 100px auto 0;
width: 70px;
text-align: center;
}
.spinner > div {
width: 18px;
height: 18px;
background-color: #333;
border-radius: 100%;
display: inline-block;
-webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
animation: sk-bouncedelay 1.4s infinite ease-in-out both;
}
.spinner .bounce1 {
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}
.spinner .bounce2 {
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}
@-webkit-keyframes sk-bouncedelay {
0%, 80%, 100% { -webkit-transform: scale(0) }
40% { -webkit-transform: scale(1.0) }
}
@keyframes sk-bouncedelay {
0%, 80%, 100% {
-webkit-transform: scale(0);
transform: scale(0);
} 40% {
-webkit-transform: scale(1.0);
transform: scale(1.0);
}
}
</style>
</head>
<body onload="submitForm();">
<div class="spinner">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
<form class="text-center mt-2" method="{{ $method }}" action="{{ $action }}">
<p>Forwarding to secure payment provider.</p>
<p>
If you are not automatically redirected to the payment website with in
<span id="countdown">10</span>
seconds...
</p>

@foreach($inputs as $name => $value)
<input type="hidden" name="{{ $name }}" value="{{ $value }}">
@endforeach

<button type="submit">Click here</button>
</form>
<script>
// Total seconds to wait
var seconds = 10;
function submitForm() {
document.forms[0].submit();
}
function countdown() {
seconds = seconds - 1;
if (seconds <= 0) {
// submit the form
submitForm();
} else {
// Update remaining seconds
document.getElementById("countdown").innerHTML = seconds;
// Count down using javascript
window.setTimeout("countdown()", 1000);
}
}
// Run countdown function
countdown();
</script>
</body>
</html>
26 changes: 11 additions & 15 deletions src/Abstracts/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,20 @@ public function getInvoice()
/**
* Create payment redirection form.
*
* @param $url
* @param array $data
* @param $action
* @param array $inputs
* @param string $method
* @return string
*/
public function createRedirectionForm($url, array $data)
public function redirectWithForm($action, array $inputs = [], $method = 'POST')
{
$output = '<html><head><meta charset="utf-8" />';
$output .= '<script>function pay() { document.forms["pay"].submit(); }</script>';
$output .= '</head><body onload="pay();"><form name="pay" method="post" action="'.$url.'">';
if ( !empty($data) ) {
foreach ($data as $key => $value) {
$output.='<input type="hidden" name="'.$key.'" value="'.$value.'">';
}
}
$output.='<input type="submit" value="doing the payment...">';
$output.='</form></body></html>';

return $output;
return view('shetabitPayment::redirectForm')->with(
[
'action' => $action,
'inputs' => $inputs,
'method' => $method,
]
);
}

/**
Expand Down
29 changes: 21 additions & 8 deletions src/Provider/PaymentServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,27 @@ class PaymentServiceProvider extends ServiceProvider
*/
public function boot()
{
$this->loadViewsFrom(__DIR__ . '/resources/views', 'shetabitPayment');

/**
* Configurations that needs to be done by user.
*/
$this->publishes([
__DIR__.'/../Config/payment.php' => config_path('payment.php'),
], 'config');
$this->publishes(
[
__DIR__.'/../../Config/payment.php' => config_path('payment.php'),
],
'config'
);

/**
* Bind to service container.
* Views that needs to be modified by user.
*/
$this->app->bind('shetabit-payment', function () {
return new PaymentManager(config('payment'));
});
$this->publishes(
[
__DIR__ . '/../../resources/views' => resource_path('views/vendor/shetabitPayment')
],
'views'
);
}

/**
Expand All @@ -36,6 +44,11 @@ public function boot()
*/
public function register()
{
//
/**
* Bind to service container.
*/
$this->app->bind('shetabit-payment', function () {
return new PaymentManager(config('payment'));
});
}
}

0 comments on commit 745f5a7

Please sign in to comment.