Skip to content

Commit

Permalink
- [X] secure post url
Browse files Browse the repository at this point in the history
  • Loading branch information
aemaddin committed Feb 17, 2025
1 parent 3ba1011 commit 6d3a289
Show file tree
Hide file tree
Showing 31 changed files with 274 additions and 276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,34 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
if (!Schema::hasColumn('users', 'first_name')) {
if (! Schema::hasColumn('users', 'first_name')) {
$table->string('first_name')->nullable();
}

if (!Schema::hasColumn('users', 'last_name')) {
if (! Schema::hasColumn('users', 'last_name')) {
$table->string('last_name')->nullable();
}

if (!Schema::hasColumn('users', 'phone')) {
if (! Schema::hasColumn('users', 'phone')) {
$table->string('phone')->nullable();
}

if (!Schema::hasColumn('users', 'phone_code')) {
if (! Schema::hasColumn('users', 'phone_code')) {
$table->string('phone_code')->nullable();
}

if (!Schema::hasColumn('users', 'email')) {
if (! Schema::hasColumn('users', 'email')) {
$table->string('email')->nullable();
}

if (!Schema::hasColumn('users', 'tap_id')) {
if (! Schema::hasColumn('users', 'tap_id')) {
$table->string('tap_id')->nullable()->index();
$table->string('card_brand')->nullable();
$table->string('card_last_four', 4)->nullable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class extends Migration {
/**
* Run the migrations.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class extends Migration {
/**
* Run the migrations.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Cashier.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Asciisd\Cashier;

use Asciisd\Cashier\Contracts\Billable;
use Asciisd\Cashier\Traits\ManagesAppDetails;
use Asciisd\Cashier\Traits\ManagesSupportOptions;
use Money\Currencies\ISOCurrencies;
use Money\Currency;
use Money\Formatter\IntlMoneyFormatter;
use Money\Money;
use NumberFormatter;
use Asciisd\Cashier\Contracts\Billable;

class Cashier
{
Expand Down Expand Up @@ -55,7 +55,7 @@ class Cashier
public static function tapOptions(array $options = []): array
{
return array_merge([
'api_key' => config('cashier.secret'),
'api_key' => config('cashier.secret'),
'tap_version' => static::TAP_VERSION,
], $options);
}
Expand Down
146 changes: 73 additions & 73 deletions src/Concerns/ManagesCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,60 @@ public function tapId(): ?string
*/
public function hasTapId(): bool
{
return !is_null($this->tap_id);
return ! is_null($this->tap_id);
}

/**
* Update the underlying Tap customer information for the model.
*
* @param array $options
* @return array|TapCustomer|TapObject
*/
public function updateTapCustomer(array $options = []): TapObject|array|TapCustomer
{
return TapCustomer::update(
$this->tap_id, $options, $this->tapOptions()
);
}

/**
* Get the default Tap API options for the current Billable model.
*
* @param array $options
* @return array
*/
public function tapOptions(array $options = []): array
{
return Cashier::tapOptions($options);
}

/**
* Get the Tap customer instance for the current user or create one.
*
* @param array $options
* @return TapCustomer
* @throws InvalidCustomer
*/
public function createOrGetTapCustomer(array $options = []): TapCustomer
{
if ($this->tap_id) {
return $this->asTapCustomer();
}

return $this->createAsTapCustomer($options);
}

/**
* Get the Tap customer for the model.
*
* @return TapCustomer
* @throws InvalidCustomer
*/
public function asTapCustomer(): TapCustomer
{
$this->assertCustomerExists();

return TapCustomer::retrieve($this->tap_id, $this->tapOptions());
}

/**
Expand All @@ -39,15 +92,15 @@ public function hasTapId(): bool
*/
protected function assertCustomerExists(): void
{
if (!$this->tap_id) {
if (! $this->tap_id) {
throw InvalidCustomer::nonCustomer($this);
}
}

/**
* Create a Tap customer for the given model.
*
* @param array $options
* @param array $options
* @return TapCustomer
* @throws InvalidCustomer
*/
Expand All @@ -73,46 +126,34 @@ public function createAsTapCustomer(array $options = []): TapCustomer
return $customer;
}

/**
* Update the underlying Tap customer information for the model.
*
* @param array $options
* @return array|TapCustomer|TapObject
*/
public function updateTapCustomer(array $options = []): TapObject|array|TapCustomer
public function tapCustomerFields(): array
{
return TapCustomer::update(
$this->tap_id, $options, $this->tapOptions()
);
return [
'first_name' => $this->tapFirstName(),
'last_name' => $this->tapLastName(),
'email' => $this->tapEmail(),
'phone' => $this->tapPhone()
];
}

/**
* Get the Tap customer instance for the current user or create one.
* Get the first name used to create the customer in Tap.
*
* @param array $options
* @return TapCustomer
* @throws InvalidCustomer
* @return string
*/
public function createOrGetTapCustomer(array $options = []): TapCustomer
public function tapFirstName(): string
{
if ($this->tap_id) {
return $this->asTapCustomer();
}

return $this->createAsTapCustomer($options);
return $this->first_name;
}

/**
* Get the Tap customer for the model.
* Get the last name used to create the customer in Tap.
*
* @return TapCustomer
* @throws InvalidCustomer
* @return string
*/
public function asTapCustomer(): TapCustomer
public function tapLastName(): string
{
$this->assertCustomerExists();

return TapCustomer::retrieve($this->tap_id, $this->tapOptions());
return $this->last_name;
}

/**
Expand All @@ -134,34 +175,14 @@ public function tapPhone(): array
{
return [
'country_code' => $this->phone_code,
'number' => $this->phone
'number' => $this->phone
];
}

/**
* Get the first name used to create the customer in Tap.
*
* @return string
*/
public function tapFirstName(): string
{
return $this->first_name;
}

/**
* Get the last name used to create the customer in Tap.
*
* @return string
*/
public function tapLastName(): string
{
return $this->last_name;
}

/**
* Apply a coupon to the billable entity.
*
* @param string $coupon
* @param string $coupon
* @return void
* @throws InvalidCustomer
*/
Expand All @@ -185,25 +206,4 @@ public function preferredCurrency(): string
{
return config('cashier.currency');
}

/**
* Get the default Tap API options for the current Billable model.
*
* @param array $options
* @return array
*/
public function tapOptions(array $options = []): array
{
return Cashier::tapOptions($options);
}

public function tapCustomerFields(): array
{
return [
'first_name' => $this->tapFirstName(),
'last_name' => $this->tapLastName(),
'email' => $this->tapEmail(),
'phone' => $this->tapPhone()
];
}
}
22 changes: 11 additions & 11 deletions src/Concerns/ManagesInvoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@ public static function tapInvoices($limit = 25): TapObject|array
public function createTapInvoice($amount, $trading_account, $currency = 'KWD', $options = [])
{
return Invoice::create(array_merge([
"due" => now()->getPreciseTimestamp(3),
"expiry" => now()->addDays(10)->getPreciseTimestamp(3),
"due" => now()->getPreciseTimestamp(3),
"expiry" => now()->addDays(10)->getPreciseTimestamp(3),
"customer" => [
"id" => $this->tap_id,
],
"order" => [
"amount" => $amount,
"order" => [
"amount" => $amount,
"currency" => $currency,
"items" => [
"items" => [
[
"amount" => $amount,
"currency" => $currency,
"amount" => $amount,
"currency" => $currency,
"description" => "Deposit on account #".$trading_account,
"name" => "Deposit",
"quantity" => 1,
"name" => "Deposit",
"quantity" => 1,
],
],
],
"post" => ['url' => url('/tap/webhook')],
"redirect" => ['url' => url(config('cashier.redirect_url'))],
"post" => ['url' => url('/tap/webhook', secure: true)],
"redirect" => ['url' => url(config('cashier.redirect_url'), secure: true)],

], $options), Cashier::tapOptions());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Concerns/ManagesPaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ trait ManagesPaymentMethods
*/
public function hasPaymentMethod(): bool
{
return (bool) $this->card_brand;
return (bool)$this->card_brand;
}

/**
* Get the default payment method for the entity.
*/
public function defaultPaymentMethod(): ?string
{
if (!$this->hasTapId()) {
if (! $this->hasTapId()) {
return null;
}

Expand Down
16 changes: 8 additions & 8 deletions src/Concerns/PerformsCharges.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ trait PerformsCharges
*
* allowed payment methods is ['src_kw.knet', 'src_all', 'src_card']
*
* @param int $amount
* @param string $paymentMethod
* @param array $options
* @param int $amount
* @param string $paymentMethod
* @param array $options
* @return Payment
*
* @throws PaymentActionRequired
Expand All @@ -36,16 +36,16 @@ public function charge(int $amount, string $paymentMethod, array $options = []):
$options['amount'] = $amount;
$options['source'] = ['id' => $paymentMethod];

if (!$this->hasTapId()) {
if (! $this->hasTapId()) {
$this->createAsTapCustomer();
}

$options['reference'] = ['transaction' => rand()];
$options['customer'] = ['id' => $this->tap_id];
$options['redirect'] = ['url' => url(config('cashier.redirect_url'))];
$options['redirect'] = ['url' => url(config('cashier.redirect_url'), secure: true)];

if (config('cashier.webhook.secret')) {
$options['post'] = ['url' => url('/tap/webhook', secure: false)];
$options['post'] = ['url' => url('/tap/webhook', secure: true)];
}

$payment = new Payment(
Expand All @@ -60,8 +60,8 @@ public function charge(int $amount, string $paymentMethod, array $options = []):
/**
* Refund a customer for a charge.
*
* @param string $charge
* @param array $options
* @param string $charge
* @param array $options
* @return array|Customer|Refund|TapObject
*/
public function refund(string $charge, array $options = []): TapObject|array|Customer|Refund
Expand Down
Loading

0 comments on commit 6d3a289

Please sign in to comment.