Skip to content

Commit

Permalink
Merge pull request #9 from ahmedsaoud31/master
Browse files Browse the repository at this point in the history
Use blade as html verification templates
  • Loading branch information
peter-tharwat authored Oct 7, 2022
2 parents 9750bc5 + ae16c55 commit 634653a
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 117 deletions.
27 changes: 27 additions & 0 deletions resources/views/html/fawry.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<link rel='stylesheet' href="https://atfawry.fawrystaging.com/atfawry/plugin/assets/payments/css/fawrypay-payments.css">
<script type='text/javascript' src="{{ $data['fawry_url'] }}atfawry/plugin/assets/payments/js/fawrypay-payments.js"></script>
<script>
const chargeRequest = {};
chargeRequest.language= "ar-eg";
chargeRequest.merchantCode= "{{ $data['fawry_merchant'] }}";
chargeRequest.merchantRefNumber= "{{ $data['payment_id'] }}";
chargeRequest.customer = {};
chargeRequest.customer.name = "{{ $data['user_name'] }}";
chargeRequest.customer.mobile = "{{ $data['user_phone'] }}";
chargeRequest.customer.email = "{{ $data['user_email'] }}";
chargeRequest.customer.customerProfileId = "{{ $data['user_id'] }}";
chargeRequest.order = {};
chargeRequest.order.description = "Credit";
chargeRequest.order.expiry = '';
chargeRequest.order.orderItems = [];
const item = {};
item.productSKU = 1;
item.description = 'Credit';
item.price = "{{ $data['amount'] }}";
item.quantity = "{{ $data['item_quantity'] }}";
chargeRequest.order.orderItems.push(item);
chargeRequest.signature = "{{ $data['secret'] }}";
setTimeout(function(){
FawryPay.checkout(chargeRequest,'{{ route($model->verify_route_name, ["payment" => "fawry"]) }}', '{{ route($model->verify_route_name, ["payment" => "fawry"]) }}');
},100);
</script>
44 changes: 44 additions & 0 deletions resources/views/html/hyper_pay.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<form action="{{ route($model->verify_route_name, ['payment' => 'hyperpay']) }}" class='paymentWidgets' data-brands="{{ $brand }}"></form>
<script src="{{ $model->hyperpay_base_url }}"/v1/paymentWidgets.js?checkoutId="{{ $model->payment_id }}"></script>
<script type='text/javascript'>
const subTotalAmount = parseFloat({{ $model->amount }});
const shippingAmount = 0;
const taxAmount = 0;
const currency = "{{ $model->currency }}";
const applePayTotalLabel = "{{ $model->app_name }}";
function getAmount() {
return ((subTotalAmount + shippingAmount + taxAmount)).toFixed(2);
}
function getLineItems() {
return [{
label: 'Subtotal',
amount: (subTotalAmount).toFixed(2)
}, {
label: 'Shipping',
amount: (shippingAmount).toFixed(2)
}, {
label: 'Tax',
amount: (taxAmount).toFixed(2)
}];
}
const wpwlOptions = {
applePay: {
displayName: "{{ $model->app_name }}",
total: {
label: "{{ $model->app_name }}"
},
paymentTarget:'_top',
merchantCapabilities: ['supports3DS'],
supportedNetworks: ['mada','masterCard', 'visa' ],
supportedCountries: ['SA'],
}
};
wpwlOptions.createCheckout = function() {
return $.post("{{ route($model->verify_route_name, ['payment' => 'hyperpay']) }}")
.then(function(response) {
return response.checkoutId;
});
};
</script>
16 changes: 16 additions & 0 deletions resources/views/html/kashier.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<body>
<script id="kashier-iFrame"
src="{{ $model->kashier_url }}/kashier-checkout.js"
data-amount="{{ $model->amount }}"
data-description="Credit"
data-mode="{{ $model->kashier_mode }}"
data-hash="{{ $data['hash'] }}"
data-currency="{{ $data['currency'] "
data-orderId="{{ $data['order_id'] "
data-allowedMethods="card"
data-merchantId="{{ $data['mid'] }}"
data-merchantRedirect="{{ $data['redirect_back'] }}"
data-store="{{ $model->app_name }}"
data-type="external" data-display="ar">
</script>
</body>
36 changes: 6 additions & 30 deletions src/Classes/FawryPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
class FawryPayment implements PaymentInterface
{
use SetVariables, SetRequiredFields;
private $fawry_url;
private $fawry_secret;
private $fawry_merchant;
private $verify_route_name;
public $fawry_url;
public $fawry_secret;
public $fawry_merchant;
public $verify_route_name;

public function __construct()
{
Expand Down Expand Up @@ -55,7 +55,7 @@ public function pay($amount = null, $user_id = null, $user_first_name = null, $u
'unique_id' => $unique_id,
'item_id' => 1,
'item_quantity' => 1,
'amount' => $amount,
'amount' => $this->amount,
'payment_id'=>$unique_id
];

Expand Down Expand Up @@ -102,31 +102,7 @@ public function verify(Request $request)

private function generate_html($data): string
{
return "<link rel='stylesheet' href='https://atfawry.fawrystaging.com/atfawry/plugin/assets/payments/css/fawrypay-payments.css'><script type='text/javascript' src='" . $data['fawry_url'] . "atfawry/plugin/assets/payments/js/fawrypay-payments.js'></script><script>
const chargeRequest = {};
chargeRequest.language= 'ar-eg';
chargeRequest.merchantCode= '" . $data['fawry_merchant'] . "';
chargeRequest.merchantRefNumber= '" . $data['payment_id'] . "';
chargeRequest.customer = {};
chargeRequest.customer.name = '" . $data['user_name'] . "';
chargeRequest.customer.mobile = '" . $data['user_phone'] . "';
chargeRequest.customer.email = '" . $data['user_email'] . "';
chargeRequest.customer.customerProfileId = '" . $data['user_id'] . "';
chargeRequest.order = {};
chargeRequest.order.description = 'Credit';
chargeRequest.order.expiry = '';
chargeRequest.order.orderItems = [];
const item = {};
item.productSKU =1;
item.description ='Credit';
item.price =" . $data['amount'] . ";
item.quantity =" . $data['item_quantity'] . ";
chargeRequest.order.orderItems.push(item);
chargeRequest.signature = '" . $data['secret'] . "';
setTimeout(function(){
FawryPay.checkout(chargeRequest,'" . route($this->verify_route_name, ['payment' => "fawry"]) . "','" . route($this->verify_route_name, ['payment' => "fawry"]) . "');
},100);
</script>";
return view('nafezly::html.fawry', ['model' => $this, 'data' => $data])->render();
}

}
82 changes: 22 additions & 60 deletions src/Classes/HyperPayPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ class HyperPayPayment
{
use SetVariables, SetRequiredFields;
private $hyperpay_url;
private $hyperpay_base_url;
public $hyperpay_base_url;
private $hyperpay_token;
private $hyperpay_credit_id;
private $hyperpay_mada_id;
private $hyperpay_apple_id;
private $app_name;
private $verify_route_name;
public $app_name;
public $verify_route_name;
public $payment_id;

public function __construct()
{
Expand Down Expand Up @@ -50,7 +51,7 @@ public function pay($amount = null, $user_id = null, $user_first_name = null, $u
$this->checkRequiredFields($required_fields, 'HYPERPAY', func_get_args());

$data = http_build_query([
'entityId' => $this->getEntityId($source),
'entityId' => $this->getEntityId($this->source),
'amount' => $this->amount,
'currency' => $this->currency,
'paymentType' => 'DB',
Expand Down Expand Up @@ -79,11 +80,11 @@ public function pay($amount = null, $user_id = null, $user_first_name = null, $u
return curl_error($ch);
}
curl_close($ch);
$payment_id = json_decode($responseData)->id;
Cache::forever($payment_id . '_source', $source);
$this->payment_id = json_decode($responseData)->id;
Cache::forever($this->payment_id . '_source', $this->source);
return [
'payment_id' => $payment_id,
'html' => $this->generate_html($source, $amount, $payment_id),
'payment_id' => $this->payment_id,
'html' => $this->generate_html(),
'redirect_url'=>""
];
}
Expand Down Expand Up @@ -130,59 +131,9 @@ public function verify(Request $request)
}
}

private function generate_html($source, $amount, $payment_id): string
public function generate_html(): string
{

$form_brands = "VISA MASTER";
if ($source == "MADA")
$form_brands = "MADA";
elseif ($source == "APPLE")
$form_brands = "APPLEPAY";

return "<form action='" . route($this->verify_route_name, ['payment' => 'hyperpay']) . "' class='paymentWidgets' data-brands='" . $form_brands . "'></form>
<script src=" . $this->hyperpay_base_url . "/v1/paymentWidgets.js?checkoutId=" . $payment_id . "></script>
<script type='text/javascript'>
const subTotalAmount = parseFloat(\" . $amount . \");
const shippingAmount = 0;
const taxAmount = 0;
const currency = '" . $this->currency . "';
const applePayTotalLabel = '" . $this->app_name . "';
function getAmount() {
return ((subTotalAmount + shippingAmount + taxAmount)).toFixed(2);
}
function getLineItems() {
return [{
label: 'Subtotal',
amount: (subTotalAmount).toFixed(2)
}, {
label: 'Shipping',
amount: (shippingAmount).toFixed(2)
}, {
label: 'Tax',
amount: (taxAmount).toFixed(2)
}];
}
const wpwlOptions = {
applePay: {
displayName: '" . $this->app_name . "',
total: {
label: '" . $this->app_name . ".'
},
paymentTarget:'_top',
merchantCapabilities: ['supports3DS'],
supportedNetworks: ['mada','masterCard', 'visa' ],
supportedCountries: ['SA'],
}
};
wpwlOptions.createCheckout = function() {
return $.post('" . route($this->verify_route_name, ['payment' => 'hyperpay']) . "')
.then(function(response) {
return response.checkoutId;
});
};
</script>";
return view('nafezly::html.hyper_pay', ['model' => $this, 'brand' => $this->getBrand()])->render();
}

private function getEntityId($source)
Expand All @@ -199,6 +150,17 @@ private function getEntityId($source)
return "";
}
}

private function getBrand()
{
$form_brands = "VISA MASTER";
if ($this->source == "MADA"){
$form_brands = "MADA";
}elseif ($this->source == "APPLE"){
$form_brands = "APPLEPAY";
}
return $form_brands;
}
}


24 changes: 6 additions & 18 deletions src/Classes/KashierPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
class KashierPayment implements PaymentInterface
{
use SetVariables, SetRequiredFields;
private $kashier_url;
private $kashier_mode;
public $kashier_url;
public $kashier_mode;
private $kashier_account_key;
private $kashier_iframe_key;
private $app_name;
public $app_name;
private $verify_route_name;

public function __construct()
Expand Down Expand Up @@ -66,7 +66,7 @@ public function pay($amount = null, $user_id = null, $user_first_name = null, $u

return [
'payment_id' => $payment_id,
'html' => $this->generate_html($amount, $data),
'html' => $this->generate_html($data),
'redirect_url'=>""
];

Expand Down Expand Up @@ -120,21 +120,9 @@ public function verify(Request $request): array
* @param $data
* @return string
*/
private function generate_html($amount, $data): string
private function generate_html($data): string
{
return '<body><script id="kashier-iFrame"
src="' . $this->kashier_url . '/kashier-checkout.js"
data-amount="' . $amount . '"
data-description="Credit"
data-mode="' . $this->kashier_mode . '"
data-hash="' . $data["hash"] . '"
data-currency="' . $data["currency"] . '"
data-orderId="' . $data["order_id"] . '"
data-allowedMethods="card"
data-merchantId="' . $data["mid"] . '"
data-merchantRedirect="' . $data["redirect_back"] . '"
data-store="' . $this->app_name . '"
data-type="external" data-display="ar"></script></body>';
return view('nafezly::html.kashier', ['model' => $this, 'data' => $data])->render();
}

}
5 changes: 4 additions & 1 deletion src/NafezlyPaymentsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public function boot()
{
$this->configure();
$this->registerPublishing();

$this->loadViewsFrom(__DIR__.'/../resources/views', 'nafezly');
$this->publishes([
__DIR__.'/../resources/views' => resource_path('views/vendor/nafezly'),
]);
}

/**
Expand Down
16 changes: 8 additions & 8 deletions src/Traits/SetVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

trait SetVariables
{
private $user_id = null;
private $user_first_name = null;
private $user_last_name = null;
private $user_email = null;
private $user_phone = null;
private $source = null;
private $currency = null;
private $amount = null;
public $user_id = null;
public $user_first_name = null;
public $user_last_name = null;
public $user_email = null;
public $user_phone = null;
public $source = null;
public $currency = null;
public $amount = null;

/**
* Sets user ID
Expand Down

0 comments on commit 634653a

Please sign in to comment.