-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
563 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
|
||
namespace Dystcz\LunarRewards\Tests\Stubs\Lunar; | ||
|
||
use Lunar\Base\Addressable; | ||
use Lunar\Base\Purchasable; | ||
use Lunar\Base\TaxDriver; | ||
use Lunar\Base\ValueObjects\Cart\TaxBreakdown; | ||
use Lunar\Base\ValueObjects\Cart\TaxBreakdownAmount; | ||
use Lunar\DataTypes\Price; | ||
use Lunar\Models\CartLine; | ||
use Lunar\Models\Currency; | ||
use Lunar\Models\ProductVariant; | ||
use Lunar\Models\TaxRateAmount; | ||
|
||
class TestTaxDriver implements TaxDriver | ||
{ | ||
/** | ||
* The taxable shipping address. | ||
*/ | ||
protected ?Addressable $shippingAddress = null; | ||
|
||
/** | ||
* The taxable billing address. | ||
*/ | ||
protected ?Addressable $billingAddress = null; | ||
|
||
/** | ||
* The currency model. | ||
*/ | ||
protected Currency $currency; | ||
|
||
/** | ||
* The purchasable item. | ||
*/ | ||
protected Purchasable $purchasable; | ||
|
||
/** | ||
* The cart line model. | ||
*/ | ||
protected CartLine $cartLine; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setShippingAddress(?Addressable $address = null): self | ||
{ | ||
$this->shippingAddress = $address; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setCurrency(Currency $currency): self | ||
{ | ||
$this->currency = $currency; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setBillingAddress(?Addressable $address = null): self | ||
{ | ||
$this->billingAddress = $address; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setPurchasable(Purchasable $purchasable): self | ||
{ | ||
$this->purchasable = $purchasable; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Set the cart line. | ||
*/ | ||
public function setCartLine(CartLine $cartLine): self | ||
{ | ||
$this->cartLine = $cartLine; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getBreakdown($subTotal): TaxBreakdown | ||
{ | ||
$breakdown = new TaxBreakdown; | ||
|
||
$currency = Currency::first() ?: Currency::factory()->create(); | ||
|
||
$taxAmount = TaxRateAmount::factory()->create(); | ||
|
||
$result = round($subTotal * ($taxAmount->percentage / 100)); | ||
|
||
$variant = ProductVariant::factory()->create(); | ||
|
||
$amount = new TaxBreakdownAmount( | ||
price: new Price((int) $result, $currency, $variant->getUnitQuantity()), | ||
description: $taxAmount->taxRate->name, | ||
identifier: "tax_rate_{$taxAmount->taxRate->id}", | ||
percentage: $taxAmount->percentage | ||
); | ||
|
||
$breakdown->addAmount($amount); | ||
|
||
return $breakdown; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Dystcz\LunarRewards\Tests\Stubs\Lunar; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class TestUrlGenerator | ||
{ | ||
/** | ||
* The instance of the model. | ||
* | ||
* @var \Illuminate\Database\Eloquent\Model | ||
*/ | ||
protected $model; | ||
|
||
/** | ||
* Handle the URL generation. | ||
*/ | ||
public function handle(Model $model): void | ||
{ | ||
// ... | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Dystcz\LunarRewards\Tests\Stubs\Users; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Foundation\Auth\User as Authenticatable; | ||
use Illuminate\Notifications\Notifiable; | ||
use Lunar\Base\Traits\LunarUser; | ||
|
||
class User extends Authenticatable | ||
{ | ||
use HasFactory; | ||
use LunarUser; | ||
use Notifiable; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'name', | ||
'email', | ||
'password', | ||
]; | ||
|
||
/** | ||
* The attributes that should be hidden for arrays. | ||
* | ||
* @var array | ||
*/ | ||
protected $hidden = [ | ||
'password', | ||
'remember_token', | ||
]; | ||
|
||
/** | ||
* The attributes that should be cast to native types. | ||
* | ||
* @var array | ||
*/ | ||
protected $casts = [ | ||
'email_verified_at' => 'datetime', | ||
]; | ||
|
||
/** | ||
* Return a new factory instance for the model. | ||
*/ | ||
protected static function newFactory(): UserFactory | ||
{ | ||
return UserFactory::new(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Dystcz\LunarRewards\Tests\Stubs\Users; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Support\Str; | ||
|
||
/** | ||
* @extends Factory<Model> | ||
*/ | ||
class UserFactory extends Factory | ||
{ | ||
/** | ||
* The name of the factory's corresponding model. | ||
* | ||
* @var string | ||
*/ | ||
protected $model = User::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
*/ | ||
public function definition(): array | ||
{ | ||
return [ | ||
'name' => $this->faker->name(), | ||
'email' => $this->faker->unique()->safeEmail(), | ||
'email_verified_at' => now(), | ||
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password | ||
'remember_token' => Str::random(10), | ||
]; | ||
} | ||
|
||
/** | ||
* Indicate that the model's email address should be unverified. | ||
* | ||
* @return Factory | ||
*/ | ||
public function unverified(): UserFactory | ||
{ | ||
return $this->state(function (array $attributes) { | ||
return [ | ||
'email_verified_at' => null, | ||
]; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Dystcz\LunarRewards\Tests\Stubs\Users; | ||
|
||
use LaravelJsonApi\Eloquent\Fields\ID; | ||
use LaravelJsonApi\Eloquent\Schema; | ||
|
||
class UserSchema extends Schema | ||
{ | ||
/** | ||
* The model the schema corresponds to. | ||
*/ | ||
public static string $model = User::class; | ||
|
||
/** | ||
* Get the resource fields. | ||
*/ | ||
public function fields(): array | ||
{ | ||
return [ | ||
ID::make(), | ||
]; | ||
} | ||
|
||
/** | ||
* Get the JSON:API resource type. | ||
*/ | ||
public static function type(): string | ||
{ | ||
return 'users'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.