Add cors for buy now buttons

This commit is contained in:
Hillel Coren 2017-03-21 15:41:01 +02:00
parent e40791c616
commit a06fe489ba
9 changed files with 122 additions and 53 deletions

View File

@ -360,9 +360,15 @@ class OnlinePaymentController extends BaseController
} }
if ($gatewayTypeAlias) { if ($gatewayTypeAlias) {
return redirect()->to($invitation->getLink('payment') . "/{$gatewayTypeAlias}"); $link = $invitation->getLink('payment') . "/{$gatewayTypeAlias}";
} else { } else {
return redirect()->to($invitation->getLink()); $link = $invitation->getLink();
}
if (filter_var(Input::get('return_link'), FILTER_VALIDATE_BOOLEAN)) {
return $link;
} else {
return redirect()->to($link);
} }
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
namespace App\Http; namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel; use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel class Kernel extends HttpKernel
@ -34,6 +34,6 @@ class Kernel extends HttpKernel
'permissions.required' => 'App\Http\Middleware\PermissionsRequired', 'permissions.required' => 'App\Http\Middleware\PermissionsRequired',
'guest' => 'App\Http\Middleware\RedirectIfAuthenticated', 'guest' => 'App\Http\Middleware\RedirectIfAuthenticated',
'api' => 'App\Http\Middleware\ApiCheck', 'api' => 'App\Http\Middleware\ApiCheck',
'cors' => '\App\Http\Middleware\Cors', 'cors' => '\Barryvdh\Cors\HandleCors',
]; ];
} }

View File

@ -1,22 +0,0 @@
<?php
namespace App\Http\Middleware;
use Closure;
class Cors
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST');
}
}

View File

@ -41,6 +41,7 @@ class SaveClientPortalSettings extends Request
$input['client_view_css'] = HTMLUtils::sanitize($this->client_view_css); $input['client_view_css'] = HTMLUtils::sanitize($this->client_view_css);
} }
if (Utils::isNinja()) {
if ($this->custom_link == 'subdomain') { if ($this->custom_link == 'subdomain') {
$subdomain = substr(strtolower($input['subdomain']), 0, MAX_SUBDOMAIN_LENGTH); $subdomain = substr(strtolower($input['subdomain']), 0, MAX_SUBDOMAIN_LENGTH);
$input['subdomain'] = preg_replace('/[^a-zA-Z0-9_\-\.]/', '', $subdomain); $input['subdomain'] = preg_replace('/[^a-zA-Z0-9_\-\.]/', '', $subdomain);
@ -51,6 +52,7 @@ class SaveClientPortalSettings extends Request
$input['iframe_url'] = rtrim($iframeURL, '/'); $input['iframe_url'] = rtrim($iframeURL, '/');
$input['subdomain'] = null; $input['subdomain'] = null;
} }
}
$this->replace($input); $this->replace($input);

View File

@ -82,7 +82,8 @@
"predis/predis": "^1.1", "predis/predis": "^1.1",
"nwidart/laravel-modules": "^1.14", "nwidart/laravel-modules": "^1.14",
"jonnyw/php-phantomjs": "4.*", "jonnyw/php-phantomjs": "4.*",
"collizo4sky/omnipay-wepay": "^1.3" "collizo4sky/omnipay-wepay": "^1.3",
"barryvdh/laravel-cors": "^0.9.1"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~4.0", "phpunit/phpunit": "~4.0",

62
composer.lock generated
View File

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "16c087062022dc367fa7c330cb8f1bea", "hash": "5c6d080c3a38d42e07ab70bf32760976",
"content-hash": "154f02784a3e9bb390f10ec0f23068e4", "content-hash": "dcf4534113b5e62eb3f1fa6b453c82be",
"packages": [ "packages": [
{ {
"name": "agmscode/omnipay-agms", "name": "agmscode/omnipay-agms",
@ -445,6 +445,64 @@
], ],
"time": "2017-01-13 14:52:38" "time": "2017-01-13 14:52:38"
}, },
{
"name": "barryvdh/laravel-cors",
"version": "v0.9.1",
"source": {
"type": "git",
"url": "https://github.com/barryvdh/laravel-cors.git",
"reference": "9fe3dfb7198ed6df0fca333347e5c9b2db62a2f4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/barryvdh/laravel-cors/zipball/9fe3dfb7198ed6df0fca333347e5c9b2db62a2f4",
"reference": "9fe3dfb7198ed6df0fca333347e5c9b2db62a2f4",
"shasum": ""
},
"require": {
"illuminate/support": "5.1.x|5.2.x|5.3.x|5.4.x",
"php": ">=5.5.9",
"symfony/http-foundation": "~2.7|~3.0",
"symfony/http-kernel": "~2.7|~3.0"
},
"require-dev": {
"orchestra/testbench": "3.x",
"phpunit/phpunit": "^4.8|^5.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.9-dev",
"dev-develop": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"Barryvdh\\Cors\\": "src/"
},
"classmap": [
"tests"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"description": "Adds CORS (Cross-Origin Resource Sharing) headers support in your Laravel application",
"keywords": [
"api",
"cors",
"crossdomain",
"laravel"
],
"time": "2017-03-20 15:05:31"
},
{ {
"name": "barryvdh/laravel-debugbar", "name": "barryvdh/laravel-debugbar",
"version": "v2.3.2", "version": "v2.3.2",

View File

@ -157,6 +157,7 @@ return [
'Jaybizzle\LaravelCrawlerDetect\LaravelCrawlerDetectServiceProvider', 'Jaybizzle\LaravelCrawlerDetect\LaravelCrawlerDetectServiceProvider',
Codedge\Updater\UpdaterServiceProvider::class, Codedge\Updater\UpdaterServiceProvider::class,
Nwidart\Modules\LaravelModulesServiceProvider::class, Nwidart\Modules\LaravelModulesServiceProvider::class,
Barryvdh\Cors\ServiceProvider::class,
/* /*
* Application Service Providers... * Application Service Providers...

20
config/cors.php Normal file
View File

@ -0,0 +1,20 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Laravel CORS
|--------------------------------------------------------------------------
|
| allowedOrigins, allowedHeaders and allowedMethods can be set to array('*')
| to accept any value.
|
*/
'supportsCredentials' => false,
'allowedOrigins' => ['*'],
'allowedHeaders' => ['*'],
'allowedMethods' => ['*'],
'exposedHeaders' => [],
'maxAge' => 0,
];

View File

@ -84,22 +84,25 @@
} }
function buyProduct(affiliateKey, productId) { function buyProduct(affiliateKey, productId) {
window.open('{{ Utils::isNinjaDev() ? '' : NINJA_APP_URL }}/buy_now/?account_key={{ NINJA_LICENSE_ACCOUNT_KEY }}&product_id=' + productId + '&contact_key={{ Auth::user()->primaryAccount()->account_key }}' + '&redirect_url=' + window.location); window.open('{{ Utils::isNinjaDev() ? '' : NINJA_APP_URL }}/buy_now/?account_key={{ NINJA_LICENSE_ACCOUNT_KEY }}&product_id=' + productId + '&contact_key={{ Auth::user()->primaryAccount()->account_key }}' + '&redirect_url=' + window.location.href);
/* /*
var url = '{{ Utils::isNinjaDev() ? '' : NINJA_APP_URL }}/buy_now/'; var url = '{{ Utils::isNinjaDev() ? '' : NINJA_APP_URL }}/buy_now/';
var data = { $.ajax({
url: url,
type: 'POST',
data: {
'account_key': '{{ NINJA_LICENSE_ACCOUNT_KEY }}', 'account_key': '{{ NINJA_LICENSE_ACCOUNT_KEY }}',
'contact_key': '{{ Auth::user()->primaryAccount()->account_key }}', 'contact_key': '{{ Auth::user()->primaryAccount()->account_key }}',
'product_id': productId, 'product_id': productId,
'redirect_url': window.location,
'first_name': '{{ Auth::user()->first_name }}', 'first_name': '{{ Auth::user()->first_name }}',
'last_name': '{{ Auth::user()->last_name }}', 'last_name': '{{ Auth::user()->last_name }}',
'email': '{{ Auth::user()->email }}', 'email': '{{ Auth::user()->email }}',
}; 'redirect_url': window.location.href,
$.post(url, function (data) { 'return_link': true,
var w = window.open(); },
w.document.write(data); success: function(response) {
w.document.close(); openUrl(response, '/white_label')
}
}); });
*/ */
} }