Minor fixes for Square

This commit is contained in:
David Bomba 2021-10-03 13:36:43 +11:00
parent a7c4548a1c
commit 6c1ba6d40b
3 changed files with 50 additions and 29 deletions

View File

@ -15,6 +15,7 @@ namespace App\Http\Controllers\ClientPortal;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Requests\ClientPortal\Uploads\StoreUploadRequest; use App\Http\Requests\ClientPortal\Uploads\StoreUploadRequest;
use App\Libraries\MultiDB; use App\Libraries\MultiDB;
use App\Models\Account;
use App\Models\ClientContact; use App\Models\ClientContact;
use App\Models\Company; use App\Models\Company;
use App\Utils\Ninja; use App\Utils\Ninja;
@ -26,14 +27,21 @@ use Illuminate\Support\Facades\Auth;
class NinjaPlanController extends Controller class NinjaPlanController extends Controller
{ {
public function index(string $contact_key, string $company_key) public function index(string $contact_key, string $account_or_company_key)
{ {
MultiDB::findAndSetDbByCompanyKey($company_key); MultiDB::findAndSetDbByCompanyKey($account_or_company_key);
$company = Company::where('company_key', $company_key)->first(); $company = Company::where('company_key', $account_or_company_key)->first();
if(!$company){
MultiDB::findAndSetDbByAccountKey($account_or_company_key);
$account = Account::where('key', $account_or_company_key)->first();
}
else
$account = $company->account;
nlog("Ninja Plan Controller Company key found {$company->company_key}"); nlog("Ninja Plan Controller Company key found {$company->company_key}");
$account = $company->account;
if (MultiDB::findAndSetDbByContactKey($contact_key) && $client_contact = ClientContact::where('contact_key', $contact_key)->first()) if (MultiDB::findAndSetDbByContactKey($contact_key) && $client_contact = ClientContact::where('contact_key', $contact_key)->first())
{ {

View File

@ -270,6 +270,10 @@ class CreditCard
if ($api_response->isSuccess()) { if ($api_response->isSuccess()) {
$customers = $api_response->getBody(); $customers = $api_response->getBody();
$customers = json_decode($customers); $customers = json_decode($customers);
if(count(array($api_response->getBody(),1)) == 0)
$customers = false;
} else { } else {
$errors = $api_response->getErrors(); $errors = $api_response->getErrors();
} }

View File

@ -60,12 +60,16 @@ class ACH
'method' => '1', 'method' => '1',
*/ */
$response = $this->wepay_payment_driver->wepay->request('payment_bank/persist', [ try{
'client_id' => config('ninja.wepay.client_id'), $response = $this->wepay_payment_driver->wepay->request('payment_bank/persist', [
'client_secret' => config('ninja.wepay.client_secret'), 'client_id' => config('ninja.wepay.client_id'),
'payment_bank_id' => (int)$data['bank_account_id'], 'client_secret' => config('ninja.wepay.client_secret'),
]); 'payment_bank_id' => (int)$data['bank_account_id'],
]);
}
catch(\Exception $e){
throw new PaymentFailed($e->getMessage(), 400);
}
// display the response // display the response
// nlog($response); // nlog($response);
@ -202,26 +206,31 @@ class ACH
$app_fee = (config('ninja.wepay.fee_ach_multiplier') * $this->wepay_payment_driver->payment_hash->data->amount_with_fee) + config('ninja.wepay.fee_fixed'); $app_fee = (config('ninja.wepay.fee_ach_multiplier') * $this->wepay_payment_driver->payment_hash->data->amount_with_fee) + config('ninja.wepay.fee_fixed');
$response = $this->wepay_payment_driver->wepay->request('checkout/create', array( try{
// 'callback_uri' => route('payment_webhook', ['company_key' => $this->wepay_payment_driver->company_gateway->company->company_key, 'company_gateway_id' => $this->wepay_payment_driver->company_gateway->hashed_id]), $response = $this->wepay_payment_driver->wepay->request('checkout/create', array(
'unique_id' => Str::random(40), // 'callback_uri' => route('payment_webhook', ['company_key' => $this->wepay_payment_driver->company_gateway->company->company_key, 'company_gateway_id' => $this->wepay_payment_driver->company_gateway->hashed_id]),
'account_id' => $this->wepay_payment_driver->company_gateway->getConfigField('accountId'), 'unique_id' => Str::random(40),
'amount' => $this->wepay_payment_driver->payment_hash->data->amount_with_fee, 'account_id' => $this->wepay_payment_driver->company_gateway->getConfigField('accountId'),
'currency' => $this->wepay_payment_driver->client->getCurrencyCode(), 'amount' => $this->wepay_payment_driver->payment_hash->data->amount_with_fee,
'short_description' => 'Goods and Services', 'currency' => $this->wepay_payment_driver->client->getCurrencyCode(),
'type' => 'goods', 'short_description' => 'Goods and Services',
'fee' => [ 'type' => 'goods',
'fee_payer' => config('ninja.wepay.fee_payer'), 'fee' => [
'app_fee' => $app_fee, 'fee_payer' => config('ninja.wepay.fee_payer'),
], 'app_fee' => $app_fee,
'payment_method' => array( ],
'type' => 'payment_bank', 'payment_method' => array(
'payment_bank' => array( 'type' => 'payment_bank',
'id' => $token->token 'payment_bank' => array(
'id' => $token->token
)
) )
) ));
)); }
catch(\Exception $e){
throw new PaymentFailed($e->getMessage(), 500);
}
/* Merge all data and store in the payment hash*/ /* Merge all data and store in the payment hash*/
$state = [ $state = [
'server_response' => $response, 'server_response' => $response,