Skip to content

Commit

Permalink
Remove provider
Browse files Browse the repository at this point in the history
Add data
  • Loading branch information
litvinjuan committed Aug 6, 2019
1 parent 6c9fdb4 commit f3d3d84
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 63 deletions.
2 changes: 1 addition & 1 deletion database/migrations/create_payments_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CreatePaymentsTable extends Migration
$table->string('description');

$table->string('state')->default(PaymentState::defaultValue());
$table->string('provider');
$table->json('data');

$table->string('gateway_id')->nullable();

Expand Down
41 changes: 41 additions & 0 deletions src/LaravelPayments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace litvinjuan\LaravelPayments;

use Closure;
use litvinjuan\LaravelPayments\Handlers\CheckPaymentHandler;
use litvinjuan\LaravelPayments\Handlers\CompletePaymentHandler;
use litvinjuan\LaravelPayments\Handlers\PurchasePaymentHandler;
use litvinjuan\LaravelPayments\Payments\Payment;

class LaravelPayments
{

public static function purchase(Payment $payment, Closure $callback = null): Payment
{
$response = (new PurchasePaymentHandler())->handle($payment);

if ($callback) {
$callback($response);
}

return $payment;
}

public static function complete(Payment $payment, Closure $callback = null): Payment
{
$response = (new CompletePaymentHandler())->handle($payment);

if ($callback) {
$callback($response);
}

return $payment;
}

public static function check(Payment $payment): bool
{
return (new CheckPaymentHandler())->handle($payment);
}

}
41 changes: 20 additions & 21 deletions src/Payments/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
namespace litvinjuan\LaravelPayments\Payments;

use Carbon\Carbon;
use Closure;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Konekt\Enum\Eloquent\CastsEnums;
use litvinjuan\LaravelPayments\Handlers\CheckPaymentHandler;
use litvinjuan\LaravelPayments\Handlers\CompletePaymentHandler;
use litvinjuan\LaravelPayments\Handlers\PurchasePaymentHandler;
use Money\Money;

/**
Expand All @@ -23,7 +20,7 @@
* @property Money $paid
*
* @property PaymentState $state
* @property string $provider
* @property string $data
*
* @property-read Payable $payable
* @property-read Payer $payer
Expand All @@ -36,7 +33,6 @@ class Payment extends Model
{
use SoftDeletes;
use CastsEnums;
use PaymentAttributes;

protected $dates = [
'completed_at'
Expand All @@ -46,31 +42,34 @@ class Payment extends Model
'state' => PaymentState::class,
];

public function purchase(Closure $callback = null): self
public function payable(): MorphTo
{
$response = (new PurchasePaymentHandler())->handle($this);

if ($callback) {
$callback($response);
}
return $this->morphTo();
}

return $this;
public function payer(): MorphTo
{
return $this->morphTo();
}

public function complete(Closure $callback = null): self
public function getPriceAttribute(): Money
{
$response = (new CompletePaymentHandler())->handle($this);
return money($this->attributes['price']);
}

if ($callback) {
$callback($response);
}
public function setPriceAttribute(Money $money)
{
$this->attributes['price'] = $money->getAmount();
}

return $this;
public function getPaidAttribute(): Money
{
return money($this->attributes['paid']);
}

public function check(): bool
public function setPaidAttribute(Money $money)
{
return (new CheckPaymentHandler())->handle($this);
$this->attributes['paid'] = $money->getAmount();
}

}
41 changes: 0 additions & 41 deletions src/Payments/PaymentAttributes.php

This file was deleted.

0 comments on commit f3d3d84

Please sign in to comment.