mirror of
https://github.com/anikeen-com/id.git
synced 2026-11-01 21:29:32 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9731dd36ca | ||
|
|
be59602b30
|
||
|
|
fd96e559af
|
No files matched your search
@@ -180,6 +180,22 @@ instead of trusting the query string. Subscriptions work the same way
|
||||
(`$user->subscriptions()->create([...])->confirmationUrl(...)`, `&subscription=…`).
|
||||
Unconfirmed bookings are cancelled after 24 hours.
|
||||
|
||||
Physical goods need a shipping address (`first_name`, `last_name`, `address`, `postal_code`,
|
||||
`city`, `country_iso`). The user can change both addresses on the confirmation page, so read the
|
||||
shipping address from the order (or the `order.completed` webhook) before you ship. An item's
|
||||
`image_url` is copied to Anikeen ID and stays visible on the order and invoice:
|
||||
|
||||
```php
|
||||
$order = $user->orders()->create([
|
||||
'billing_address_id' => $addressId,
|
||||
'shipping_address' => ['first_name' => 'Ada', 'last_name' => 'Lovelace', 'address' => 'Main St', 'house_number' => '1', 'postal_code' => '10115', 'city' => 'Berlin', 'country_iso' => 'DE'],
|
||||
'items' => [
|
||||
['type' => 'physical', 'name' => 'T-shirt', 'unit' => 'piece', 'units' => 1, 'gross_price' => '24.90', 'image_url' => 'https://shop.test/img/shirt.png'],
|
||||
['type' => 'physical-reduced', 'name' => 'Artbook', 'unit' => 'piece', 'units' => 1, 'gross_price' => '19.95'],
|
||||
],
|
||||
]);
|
||||
```
|
||||
|
||||
`checkout()` on such a draft throws `ConfirmationRequiredException`; its `confirmationUrl`
|
||||
points to the same page. Trusted apps keep checking out directly.
|
||||
|
||||
|
||||
@@ -29,6 +29,21 @@ trait Billable
|
||||
use ManagesTransactions;
|
||||
use ManagesUserSshKeys;
|
||||
|
||||
/*
|
||||
* API results cached per instance. Declared, so Eloquent models don't take them for
|
||||
* attributes (an undeclared property goes through Model::__set and save() then fails
|
||||
* with "no such column").
|
||||
*/
|
||||
protected mixed $addressesCache = null;
|
||||
protected mixed $countriesCache = null;
|
||||
protected mixed $defaultPaymentMethodCache = null;
|
||||
protected mixed $invoicesCache = null;
|
||||
protected mixed $ordersCache = null;
|
||||
protected mixed $paymentMethodsCache = null;
|
||||
protected mixed $subscriptionsCache = null;
|
||||
protected mixed $transactionsCache = null;
|
||||
protected mixed $userDataCache = null;
|
||||
|
||||
/**
|
||||
* Get the currently authenticated user.
|
||||
*
|
||||
|
||||
@@ -31,7 +31,7 @@ trait ManagesUserBilling
|
||||
* billing_address?: array,
|
||||
* shipping_address_id?: string,
|
||||
* shipping_address?: array,
|
||||
* items: array<array{type: string, name: string, description?: string, price?: float|string, gross_price?: float|string, unit: string, units: int}>,
|
||||
* items: array<array{type: string, name: string, description?: string, image_url?: string, price?: float|string, gross_price?: float|string, unit: string, units: int}>,
|
||||
* checkout?: bool,
|
||||
* transaction_id?: string,
|
||||
* transaction?: array,
|
||||
|
||||
@@ -44,11 +44,11 @@ class Order extends BaseResource
|
||||
* company_name: null|string,
|
||||
* first_name: string,
|
||||
* last_name: string,
|
||||
* address: null|string,
|
||||
* address_2: string,
|
||||
* address: string,
|
||||
* address_2: null|string,
|
||||
* house_number: null|string,
|
||||
* city: string,
|
||||
* state: string,
|
||||
* state: null|string,
|
||||
* postal_code: string,
|
||||
* country_iso: string,
|
||||
* phone_number: null|string,
|
||||
@@ -56,7 +56,7 @@ class Order extends BaseResource
|
||||
* }
|
||||
* } $attributes The order data:
|
||||
* - billing_address: Billing address (ISO 3166-1 alpha-2 country code)
|
||||
* - shipping_address: Shipping address (first name, last name, ISO 3166-1 alpha-2 country code)
|
||||
* - shipping_address: Shipping address for physical items (first name, last name, address, postal code, city, ISO 3166-1 alpha-2 country code)
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function update(array $attributes = []): self
|
||||
|
||||
@@ -38,11 +38,11 @@ class Orders extends BaseCollection
|
||||
* company_name: null|string,
|
||||
* first_name: string,
|
||||
* last_name: string,
|
||||
* address: null|string,
|
||||
* address_2: string,
|
||||
* address: string,
|
||||
* address_2: null|string,
|
||||
* house_number: null|string,
|
||||
* city: string,
|
||||
* state: string,
|
||||
* state: null|string,
|
||||
* postal_code: string,
|
||||
* country_iso: string,
|
||||
* phone_number: null|string,
|
||||
@@ -51,15 +51,22 @@ class Orders extends BaseCollection
|
||||
* items: array<array{
|
||||
* type: string,
|
||||
* name: string,
|
||||
* description: string,
|
||||
* price: float|int,
|
||||
* description?: null|string,
|
||||
* image_url?: null|string,
|
||||
* price?: float|int|string,
|
||||
* gross_price?: float|int|string,
|
||||
* unit: string,
|
||||
* units: int
|
||||
* }>
|
||||
* } $attributes The order data:
|
||||
* - billing_address: Billing address (ISO 3166-1 alpha-2 country code)
|
||||
* - shipping_address: Shipping address (first name, last name, ISO 3166-1 alpha-2 country code)
|
||||
* - items: Array of order items (each with type, name, price, unit, units, and quantity)
|
||||
* - shipping_address: Shipping address for physical items (first name, last name, address, postal code, city, ISO 3166-1 alpha-2 country code)
|
||||
* - items: Array of order items:
|
||||
* - type: digital, physical or physical-reduced (VAT category)
|
||||
* - price/gross_price: net or gross unit price, one of both
|
||||
* - unit: hour, day, week, month, year, onetime or piece
|
||||
* - image_url: http(s) URL of a product image; Anikeen ID copies it, so it stays
|
||||
* visible on the order and invoice when the shop removes it later
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function create(array $attributes = []): Order
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Anikeen\Id\Tests;
|
||||
|
||||
use Anikeen\Id\Billable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class BillableModelTest extends TestCase
|
||||
{
|
||||
public function test_cached_api_results_are_not_model_attributes(): void
|
||||
{
|
||||
$user = new class extends Model {
|
||||
use Billable;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public function cacheAll(): void
|
||||
{
|
||||
foreach (['addresses', 'countries', 'defaultPaymentMethod', 'invoices', 'orders', 'paymentMethods', 'subscriptions', 'transactions', 'userData'] as $name) {
|
||||
$this->{$name.'Cache'} = 'cached';
|
||||
}
|
||||
}
|
||||
};
|
||||
$user->email = 'ada@example.com';
|
||||
|
||||
$user->cacheAll();
|
||||
|
||||
// save() would otherwise write them as columns ("no such column: ordersCache")
|
||||
$this->assertSame(['email' => 'ada@example.com'], $user->getAttributes());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user