mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Tests for apple pay
This commit is contained in:
parent
3ac9c2f286
commit
e9d9b8a137
105
app/Http/Controllers/ClientPortal/ApplePayDomainController.php
Normal file
105
app/Http/Controllers/ClientPortal/ApplePayDomainController.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\ClientPortal;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\Utils\Ninja;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ApplePayDomainController extends Controller
|
||||
{
|
||||
|
||||
private array $stripe_keys = ['d14dd26a47cecc30fdd65700bfb67b34', 'd14dd26a37cecc30fdd65700bfb55b23'];
|
||||
|
||||
private ?Company $company = null;
|
||||
|
||||
public function showAppleMerchantId(Request $request)
|
||||
{
|
||||
|
||||
/* Self Host */
|
||||
|
||||
if(Ninja::isSelfHost()){
|
||||
|
||||
$cgs = CompanyGateway::whereIn('gateway_key', $this->stripe_keys)
|
||||
->where('is_deleted', false)
|
||||
->get();
|
||||
|
||||
foreach($cgs as $cg)
|
||||
{
|
||||
|
||||
if($cg->getConfigField('appleMerchantId')){
|
||||
return response($cg->getConfigField('appleMerchantId'),200);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return response('', 400);
|
||||
}
|
||||
|
||||
/* Hosted */
|
||||
|
||||
$domain_name = $request->getHost();
|
||||
|
||||
if (strpos($domain_name, 'invoicing.co') !== false)
|
||||
{
|
||||
$subdomain = explode('.', $domain_name)[0];
|
||||
|
||||
$query = [
|
||||
'subdomain' => $subdomain,
|
||||
'portal_mode' => 'subdomain',
|
||||
];
|
||||
|
||||
if($company = MultiDB::findAndSetDbByDomain($query)){
|
||||
return $this->resolveAppleMerchantId($company);
|
||||
}
|
||||
}
|
||||
|
||||
$query = [
|
||||
'portal_domain' => $request->getSchemeAndHttpHost(),
|
||||
'portal_mode' => 'domain',
|
||||
];
|
||||
|
||||
if($company = MultiDB::findAndSetDbByDomain($query)){
|
||||
return $this->resolveAppleMerchantId($company);
|
||||
}
|
||||
|
||||
return response('', 400);
|
||||
|
||||
}
|
||||
|
||||
private function resolveAppleMerchantId($company)
|
||||
{
|
||||
|
||||
$cgs = $company->company_gateways()
|
||||
->whereIn('gateway_key', $this->stripe_keys)
|
||||
->where('is_deleted', false)
|
||||
->get();
|
||||
|
||||
foreach($cgs as $cg)
|
||||
{
|
||||
|
||||
if($cg->getConfigField('appleMerchantId')){
|
||||
return response($cg->getConfigField('appleMerchantId'),200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return response('', 400);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\ClientPortal;
|
||||
|
||||
|
@ -725,6 +725,15 @@ class StripePaymentDriver extends BaseDriver
|
||||
return (new Verify($this))->run();
|
||||
}
|
||||
|
||||
public function setDomain()
|
||||
{
|
||||
// \Stripe\ApplePayDomain::create([
|
||||
// 'domain_name' => 'example.com',
|
||||
// ],[
|
||||
// 'stripe_account' => '{{CONNECTED_ACCOUNT_ID}}',
|
||||
// ]);
|
||||
}
|
||||
|
||||
public function disconnect()
|
||||
{
|
||||
if(!$this->stripe_connect)
|
||||
|
@ -42,4 +42,5 @@ trait Uploadable
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -208,6 +208,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
|
||||
Route::resource('subscriptions', 'SubscriptionController');
|
||||
Route::post('subscriptions/bulk', 'SubscriptionController@bulk')->name('subscriptions.bulk');
|
||||
Route::get('statics', 'StaticController');
|
||||
Route::post('apple_pay/upload_file','ApplyPayController@upload');
|
||||
|
||||
});
|
||||
|
||||
|
@ -44,3 +44,4 @@ Route::get('stripe/completed', 'StripeConnectController@completed')->name('strip
|
||||
Route::get('checkout/3ds_redirect/{company_key}/{company_gateway_id}/{hash}', 'Gateways\Checkout3dsController@index')->name('checkout.3ds_redirect');
|
||||
Route::get('mollie/3ds_redirect/{company_key}/{company_gateway_id}/{hash}', 'Gateways\Mollie3dsController@index')->name('mollie.3ds_redirect');
|
||||
Route::get('gocardless/ibp_redirect/{company_key}/{company_gateway_id}/{hash}', 'Gateways\GoCardlessController@ibpRedirect')->name('gocardless.ibp_redirect');
|
||||
Route::get('.well-known/apple-developer-merchantid-domain-association', 'ClientPortal\ApplePayDomainController@showAppleMerchantId');
|
||||
|
64
tests/Feature/ApplePayDomainMerchantUrlTest.php
Normal file
64
tests/Feature/ApplePayDomainMerchantUrlTest.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\CompanyGateway;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers App\Http\Controllers\ApplePayDomainController
|
||||
*/
|
||||
class ApplePayDomainMerchantUrlTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
use MockAccountData;
|
||||
|
||||
public function setUp() :void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->makeTestData();
|
||||
|
||||
$this->withoutMiddleware(
|
||||
ThrottleRequests::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testMerchantFieldGet()
|
||||
{
|
||||
$config = new \stdClass;
|
||||
$config->publishableKey = "pk_test";
|
||||
$config->apiKey = "sk_test";
|
||||
$config->appleMerchantId = "merchant_id";
|
||||
|
||||
$cg = new CompanyGateway;
|
||||
$cg->company_id = $this->company->id;
|
||||
$cg->user_id = $this->user->id;
|
||||
$cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
|
||||
$cg->require_cvv = true;
|
||||
$cg->require_billing_address = true;
|
||||
$cg->require_shipping_address = true;
|
||||
$cg->update_details = true;
|
||||
$cg->config = encrypt(json_encode($config));
|
||||
$cg->fees_and_limits = '';
|
||||
$cg->save();
|
||||
|
||||
$response = $this->withHeaders([])->get('.well-known/apple-developer-merchantid-domain-association');
|
||||
|
||||
$arr = $response->getContent();
|
||||
$response->assertStatus(200);
|
||||
$this->assertEquals("merchant_id", $arr);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user