powerboard

This commit is contained in:
David Bomba 2024-09-06 14:26:13 +10:00
parent 9c8afcd434
commit 3de9c99d34
7 changed files with 403 additions and 1 deletions

View File

@ -156,6 +156,7 @@ class CompanyGateway extends BaseModel
'80af24a6a691230bbec33e930ab40666' => 323,
'vpyfbmdrkqcicpkjqdusgjfluebftuva' => 324, //BTPay
'91be24c7b792230bced33e930ac61676' => 325,
'b67581d804dbad1743b61c57285142ad' => 326, //Powerboard
];
protected $touches = [];

View File

@ -235,6 +235,10 @@ class Gateway extends StaticModel
],
GatewayType::ACSS => ['refund' => false, 'token_billing' => true, 'webhooks' => []]
]; // Rotessa
case 64: //b67581d804dbad1743b61c57285142ad - powerboard
return [
]
default:
return [];
}

View File

@ -154,6 +154,8 @@ class SystemLog extends Model
public const TYPE_ROTESSA = 325;
public const TYPE_POWERBOARD = 326;
public const TYPE_QUOTA_EXCEEDED = 400;
public const TYPE_UPSTREAM_FAILURE = 401;

View File

@ -0,0 +1,215 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\PaymentDrivers\CBAPowerBoard;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\CBAPowerBoardPaymentDriver;
use App\PaymentDrivers\Common\LivewireMethodInterface;
class CreditCard implements LivewireMethodInterface
{
public function __construct(public CBAPowerBoardPaymentDriver $powerboard)
{
}
public function authorizeView(array $data)
{
$intent['intent'] = $this->stripe->getSetupIntent();
return render('gateways.powerboard.credit_card.authorize', array_merge($data, $intent));
}
public function authorizeResponse($request)
{
$this->stripe->init();
// $stripe_response = json_decode($request->input('gateway_response'));
$customer = $this->powerboard->findOrCreateCustomer();
// $this->stripe->attach($stripe_response->payment_method, $customer);
// $stripe_method = $this->stripe->getStripePaymentMethod($stripe_response->payment_method);
// $this->storePaymentMethod($stripe_method, $request->payment_method_id, $customer);
return redirect()->route('client.payment_methods.index');
}
public function paymentData(array $data): array
{
// $description = $this->stripe->getDescription(false);
// $payment_intent_data = [
// 'amount' => $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()),
// 'currency' => $this->stripe->client->getCurrencyCode(),
// 'customer' => $this->stripe->findOrCreateCustomer(),
// 'description' => $description,
// 'metadata' => [
// 'payment_hash' => $this->stripe->payment_hash->hash,
// 'gateway_type_id' => GatewayType::CREDIT_CARD,
// ],
// 'setup_future_usage' => 'off_session',
// 'payment_method_types' => ['card'],
// ];
// $data['intent'] = $this->stripe->createPaymentIntent($payment_intent_data);
// $data['gateway'] = $this->stripe;
// return $data;
}
public function paymentView(array $data)
{
$data = $this->paymentData($data);
return render('gateways.stripe.credit_card.pay', $data);
}
public function livewirePaymentView(array $data): string
{
return 'gateways.powerboard.credit_card.pay_livewire';
}
public function paymentResponse(PaymentResponseRequest $request)
{
// $this->stripe->init();
// $state = [
// 'server_response' => json_decode($request->gateway_response),
// 'payment_hash' => $request->payment_hash,
// ];
// $state = array_merge($state, $request->all());
// $state['store_card'] = boolval($state['store_card']);
// if ($request->has('token') && ! is_null($request->token)) {
// $state['store_card'] = false;
// }
// $state['payment_intent'] = PaymentIntent::retrieve($state['server_response']->id, array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)]));
// $state['customer'] = $state['payment_intent']->customer;
// $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, $state);
// $this->stripe->payment_hash->save();
// $server_response = $this->stripe->payment_hash->data->server_response;
// if ($server_response->status == 'succeeded') {
// $this->stripe->logSuccessfulGatewayResponse(['response' => json_decode($request->gateway_response), 'data' => $this->stripe->payment_hash], SystemLog::TYPE_STRIPE);
// return $this->processSuccessfulPayment();
// }
// return $this->processUnsuccessfulPayment($server_response);
}
public function processSuccessfulPayment()
{
// UpdateCustomer::dispatch($this->stripe->company_gateway->company->company_key, $this->stripe->company_gateway->id, $this->stripe->client->id);
// $stripe_method = $this->stripe->getStripePaymentMethod($this->stripe->payment_hash->data->server_response->payment_method);
// $data = [
// 'payment_method' => $this->stripe->payment_hash->data->server_response->payment_method,
// 'payment_type' => PaymentType::parseCardType(strtolower($stripe_method->card->brand)) ?: PaymentType::CREDIT_CARD_OTHER,
// 'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->server_response->amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()),
// 'transaction_reference' => isset($this->stripe->payment_hash->data->payment_intent->latest_charge) ? $this->stripe->payment_hash->data->payment_intent->latest_charge : optional($this->stripe->payment_hash->data->payment_intent->charges->data[0])->id,
// 'gateway_type_id' => GatewayType::CREDIT_CARD,
// ];
// $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['amount' => $data['amount']]);
// $this->stripe->payment_hash->save();
// if ($this->stripe->payment_hash->data->store_card) {
// $customer = new \stdClass();
// $customer->id = $this->stripe->payment_hash->data->customer;
// $this->stripe->attach($this->stripe->payment_hash->data->server_response->payment_method, $customer);
// $stripe_method = $this->stripe->getStripePaymentMethod($this->stripe->payment_hash->data->server_response->payment_method);
// $this->storePaymentMethod($stripe_method, $this->stripe->payment_hash->data->payment_method_id, $customer);
// }
// $payment = $this->stripe->createPayment($data, Payment::STATUS_COMPLETED);
// SystemLogger::dispatch(
// ['response' => $this->stripe->payment_hash->data->server_response, 'data' => $data],
// SystemLog::CATEGORY_GATEWAY_RESPONSE,
// SystemLog::EVENT_GATEWAY_SUCCESS,
// SystemLog::TYPE_STRIPE,
// $this->stripe->client,
// $this->stripe->client->company,
// );
// if ($payment->invoices()->whereHas('subscription')->exists()) {
// $subscription = $payment->invoices()->first()->subscription;
// if ($subscription && array_key_exists('return_url', $subscription->webhook_configuration) && strlen($subscription->webhook_configuration['return_url']) >= 1) {
// return redirect($subscription->webhook_configuration['return_url']);
// }
// }
// return redirect()->route('client.payments.show', ['payment' => $payment->hashed_id]);
}
public function processUnsuccessfulPayment($server_response)
{
// $this->stripe->sendFailureMail($server_response->cancellation_reason);
// $message = [
// 'server_response' => $server_response,
// 'data' => $this->stripe->payment_hash->data,
// ];
// SystemLogger::dispatch(
// $message,
// SystemLog::CATEGORY_GATEWAY_RESPONSE,
// SystemLog::EVENT_GATEWAY_FAILURE,
// SystemLog::TYPE_STRIPE,
// $this->stripe->client,
// $this->stripe->client->company,
// );
// throw new PaymentFailed('Failed to process the payment.', 500);
}
private function storePaymentMethod($method, $payment_method_id, $customer)
{
// try {
// $payment_meta = new \stdClass();
// $payment_meta->exp_month = (string) $method->card->exp_month;
// $payment_meta->exp_year = (string) $method->card->exp_year;
// $payment_meta->brand = (string) $method->card->brand;
// $payment_meta->last4 = (string) $method->card->last4;
// $payment_meta->type = GatewayType::CREDIT_CARD;
// $data = [
// 'payment_meta' => $payment_meta,
// 'token' => $method->id,
// 'payment_method_id' => $payment_method_id,
// ];
// $this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]);
// } catch (\Exception $e) {
// return $this->stripe->processInternallyFailedPayment($this->stripe, $e);
// }
}
}

View File

@ -0,0 +1,134 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\PaymentDrivers;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\PaymentHash;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\Utils\HtmlEngine;
use App\Utils\Traits\MakesHash;
/**
* Class CBAPowerBoardPaymentDriver.
*/
class CBAPowerBoardPaymentDriver extends BaseDriver
{
use MakesHash;
public $token_billing = true;
public $can_authorise_credit_card = false;
public $refundable = true;
/**
* Returns the gateway types.
*/
public function gatewayTypes(): array
{
$types = [
GatewayType::CREDIT_CARD,
];
return $types;
}
public function init()
{
// $this->company_gateway->getConfigField('account_id')
return $this;
}
public function setPaymentMethod($payment_method_id)
{
$this->payment_method = $payment_method_id;
return $this;
}
/**
* View for displaying custom content of the driver.
*
* @param array $data
* @return mixed
*/
public function processPaymentView($data)
{
return $this->payment_method->paymentView($data);
}
/**
* Processing method for payment. Should never be reached with this driver.
*
* @return mixed
*/
public function processPaymentResponse($request)
{
return $this->payment_method->paymentResponse($request);
}
/**
* Detach payment method from custom payment driver.
*
* @param ClientGatewayToken $token
* @return void
*/
public function detach(ClientGatewayToken $token)
{
// Driver doesn't support this feature.
}
public function refund(Payment $payment, $amount, $return_client_response = false)
{
}
public function processWebhookRequest($request)
{
}
public function getClientRequiredFields(): array
{
return [];
}
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
{
return (new Charge($this))->tokenBilling($cgt, $payment_hash);
}
public function importCustomers()
{
}
public function auth(): bool
{
$this->init();
// try {
// $this->verifyConnect();
// return true;
// } catch(\Exception $e) {
// }
// return false;
}
}

View File

@ -0,0 +1,45 @@
<?php
use App\Models\Gateway;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Model::unguard();
$fields = new \stdClass();
$fields->accessToken = '';
// $fields->applicationId = '';
// $fields->locationId = '';
$fields->testMode = false;
$powerboard = new Gateway();
$powerboard->id = 64;
$powerboard->name = 'CBA PowerBoard';
$powerboard->provider = 'CBAPowerBoard';
$powerboard->key = 'b67581d804dbad1743b61c57285142ad';
$powerboard->sort_order = 4543;
$powerboard->is_offsite = false;
$powerboard->visible = true;
$powerboard->fields = json_encode($fields);
$powerboard->save();
}
/**
* Reverse the migrations.
*/
public function down(): void
{
//
}
};

View File

@ -88,7 +88,8 @@ class PaymentLibrariesSeeder extends Seeder
['id' => 60, 'name' => 'PayPal REST', 'provider' => 'PayPal_Rest', 'key' => '80af24a6a691230bbec33e930ab40665', 'fields' => '{"clientId":"","secret":"","signature":"","testMode":false}'],
['id' => 61, 'name' => 'PayPal Platform', 'provider' => 'PayPal_PPCP', 'key' => '80af24a6a691230bbec33e930ab40666', 'fields' => '{"testMode":false}'],
['id' => 62, 'name' => 'BTCPay', 'provider' => 'BTCPay', 'key' => 'vpyfbmdrkqcicpkjqdusgjfluebftuva', 'fields' => '{"btcpayUrl":"", "apiKey":"", "storeId":"", "webhookSecret":""}'],
['id' => 63, 'name' => 'Rotessa', 'is_offsite' => false, 'sort_order' => 22, 'provider' => 'Rotessa', 'key' => '91be24c7b792230bced33e930ac61676', 'fields' => '{"apiKey":"", "testMode":""}'],
['id' => 63, 'name' => 'Rotessa', 'is_offsite' => false, 'sort_order' => 22, 'provider' => 'Rotessa', 'key' => '91be24c7b792230bced33e930ac61676', 'fields' => '{"apiKey":"", "testMode":false}'],
['id' => 64, 'name' => 'CBA PowerBoard', 'is_offsite' => false, 'sort_order' => 26, 'provider' => 'CBAPowerBoard', 'key' => 'b67581d804dbad1743b61c57285142ad', 'fields' => '{"accessToken":"", "testMode":false}'],
];
foreach ($gateways as $gateway) {