Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add import_meta to transaction #64

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx
### Added

- Added `product` to `subscription.items[]`, see [related changelog](https://developer.paddle.com/changelog/2024/subscription-items-product?utm_source=dx&utm_medium=paddle-php-sdk)
- Added `import_meta` to `transaction`

## [1.1.2] - 2024-08-23

Expand Down
3 changes: 3 additions & 0 deletions src/Entities/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Paddle\SDK\Entities\Shared\CollectionMode;
use Paddle\SDK\Entities\Shared\CurrencyCode;
use Paddle\SDK\Entities\Shared\CustomData;
use Paddle\SDK\Entities\Shared\ImportMeta;
use Paddle\SDK\Entities\Shared\TransactionOrigin;
use Paddle\SDK\Entities\Shared\TransactionPaymentAttempt;
use Paddle\SDK\Entities\Shared\TransactionStatus;
Expand Down Expand Up @@ -64,6 +65,7 @@ private function __construct(
public Customer|null $customer,
public Discount|null $discount,
public array $availablePaymentMethods,
public ImportMeta|null $importMeta,
) {
}

Expand Down Expand Up @@ -100,6 +102,7 @@ public static function from(array $data): self
customer: isset($data['customer']) ? Customer::from($data['customer']) : null,
discount: isset($data['discount']) ? Discount::from($data['discount']) : null,
availablePaymentMethods: array_map(fn (string $item): AvailablePaymentMethods => AvailablePaymentMethods::from($item), $data['available_payment_methods'] ?? []),
importMeta: isset($data['import_meta']) ? ImportMeta::from($data['import_meta']) : null,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,12 @@ public static function cancelOperationsProvider(): \Generator
* @dataProvider getPaymentMethodChangeTransactionRequestProvider
*/
public function get_payment_method_change_transaction_hits_expected_uri(
string $id,
ResponseInterface $response,
string $expectedUri,
): void {
$this->mockClient->addResponse($response);
$this->client->subscriptions->getPaymentMethodChangeTransaction('sub_01h7zcgmdc6tmwtjehp3sh7azf');
$this->client->subscriptions->getPaymentMethodChangeTransaction($id);
$request = $this->mockClient->getLastRequest();

self::assertInstanceOf(RequestInterface::class, $request);
Expand All @@ -412,11 +413,28 @@ public function get_payment_method_change_transaction_hits_expected_uri(
public static function getPaymentMethodChangeTransactionRequestProvider(): \Generator
{
yield 'Basic' => [
'sub_01h7zcgmdc6tmwtjehp3sh7azf',
new Response(200, body: self::readRawJsonFixture('response/get_payment_method_change_transaction_entity')),
sprintf('%s/subscriptions/sub_01h7zcgmdc6tmwtjehp3sh7azf/update-payment-method-transaction', Environment::SANDBOX->baseUrl()),
];
}

/**
* @test
*/
public function get_payment_method_change_transaction_has_import_meta(): void
{
$this->mockClient->addResponse(
new Response(200, body: self::readRawJsonFixture('response/get_payment_method_change_transaction_entity_with_import_meta')),
);

$transaction = $this->client->subscriptions->getPaymentMethodChangeTransaction('sub_01h7zcgmdc6tmwtjehp3sh7azf');

self::assertNotNull($transaction->importMeta);
self::assertSame('billing_platform', $transaction->importMeta->importedFrom);
self::assertSame('9b95b0b8-e10f-441a-862e-1936a6d818ab', $transaction->importMeta->externalId);
}

/**
* @test
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
{
"data": {
"id": "txn_01h8by3n3w1zn9fsq9c93afsq3",
"status": "ready",
"customer_id": "ctm_01h8441jn5pcwrfhwh78jqt8hk",
"address_id": "add_01h848pep46enq8y372x7maj0p",
"business_id": null,
"custom_data": null,
"origin": "subscription_payment_method_change",
"collection_mode": "automatic",
"subscription_id": "sub_01h8bxswamxysj44zt5n48njwh",
"invoice_id": null,
"invoice_number": null,
"discount_id": null,
"billing_details": null,
"billing_period": {
"starts_at": "2023-08-21T11:31:08.689295Z",
"ends_at": "2023-08-21T11:31:08.689295Z"
},
"currency_code": "USD",
"created_at": "2023-08-21T11:36:30.96803057Z",
"updated_at": "2023-08-21T11:36:30.96803057Z",
"billed_at": null,
"items": [
{
"price": {
"id": "pri_01gsz8x8sawmvhz1pv30nge1ke",
"description": "Monthly (per seat)",
"name": "Monthly (per seat)",
"product_id": "pro_01gsz4t5hdjse780zja8vvr7jg",
"billing_cycle": {
"interval": "month",
"frequency": 1
},
"trial_period": null,
"tax_mode": "account_setting",
"unit_price": {
"amount": "3000",
"currency_code": "USD"
},
"unit_price_overrides": [
{
"country_codes": ["AU"],
"unit_price": {
"amount": "5000",
"currency_code": "AUD"
}
}
],
"quantity": {
"minimum": 10,
"maximum": 999
},
"status": "active",
"created_at": "2023-08-16T14:38:08.3Z",
"updated_at": "2023-08-16T14:38:08.3Z"
},
"quantity": 30,
"proration": {
"rate": "0",
"billing_period": {
"starts_at": "2023-08-21T11:31:08.689295Z",
"ends_at": "2023-09-21T11:31:08.689295Z"
}
}
}
],
"details": {
"tax_rates_used": [
{
"tax_rate": "0.08875",
"totals": {
"subtotal": "0",
"discount": "0",
"tax": "0",
"total": "0"
}
}
],
"totals": {
"subtotal": "0",
"tax": "0",
"discount": "0",
"total": "0",
"fee": null,
"credit": "0",
"credit_to_balance": "0",
"balance": "0",
"grand_total": "0",
"earnings": null,
"currency_code": "USD"
},
"adjusted_totals": {
"subtotal": "0",
"tax": "0",
"total": "0",
"grand_total": "0",
"fee": "0",
"earnings": "0",
"currency_code": "USD"
},
"payout_totals": null,
"adjusted_payout_totals": null,
"line_items": [
{
"id": "txnitm_01h8by3nfc02fjtbda5gta732d",
"price_id": "pri_01gsz8x8sawmvhz1pv30nge1ke",
"quantity": 30,
"totals": {
"subtotal": "0",
"tax": "0",
"discount": "0",
"total": "0"
},
"product": {
"id": "pro_01gsz4t5hdjse780zja8vvr7jg",
"name": "ChatApp Pro",
"description": "Everything in basic, plus access to a suite of powerful tools and features designed to take your team's productivity to the next level.",
"tax_category": "standard",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"status": "active",
"created_at": "2023-08-16T14:38:08.3Z",
"updated_at": "2023-08-16T14:38:08.3Z"
},
"tax_rate": "0.08875",
"unit_totals": {
"subtotal": "0",
"discount": "0",
"tax": "0",
"total": "0"
},
"proration": {
"rate": "0",
"billing_period": {
"starts_at": "2023-08-21T11:31:08.689295Z",
"ends_at": "2023-09-21T11:31:08.689295Z"
}
}
}
]
},
"payments": [],
"checkout": {
"url": "https://magnificent-entremet-7ae0c6.netlify.app/default/overlay?_ptxn=txn_01h8by3n3w1zn9fsq9c93afsq3"
},
"customer": {
"id": "ctm_01h8441jn5pcwrfhwh78jqt8hk",
"name": "Sam Miller",
"email": "[email protected]",
"locale": "en",
"marketing_consent": false,
"custom_data": null,
"status": "active",
"created_at": "2023-11-15T11:15:44.673Z",
"updated_at": "2023-11-15T11:15:44.673Z"
},
"address": {
"id": "add_01h848pep46enq8y372x7maj0p",
"customer_id": "ctm_01h8441jn5pcwrfhwh78jqt8hk",
"description": "Head Office",
"first_line": "4050 Jefferson Plaza, 41st Floor",
"second_line": "",
"city": "New York",
"postal_code": "10021",
"region": "NY",
"country_code": "US",
"status": "active",
"custom_data": null,
"created_at": "2023-11-15T11:15:44.673Z",
"updated_at": "2023-11-15T11:15:44.673Z"
},
"import_meta": {
"external_id": "9b95b0b8-e10f-441a-862e-1936a6d818ab",
"imported_from": "billing_platform"
}
},
"meta": {
"request_id": "e4747324-738b-4707-ac7a-7eaabb7c7a26"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,27 @@ public static function listOperationsProvider(): \Generator
];
}

/**
* @test
*/
public function list_has_import_meta(): void
{
$this->mockClient->addResponse(
new Response(200, body: self::readRawJsonFixture('response/list_default')),
);

$transactionCollection = $this->client->transactions->list(new ListTransactions());
$transactions = array_values(iterator_to_array($transactionCollection));

$transactionWithoutImportMeta = $transactions[0];
self::assertNull($transactionWithoutImportMeta->importMeta);

$transactionWithImportMeta = $transactions[1];
self::assertNotNull($transactionWithImportMeta->importMeta);
self::assertSame('billing_platform', $transactionWithImportMeta->importMeta->importedFrom);
self::assertSame('9b95b0b8-e10f-441a-862e-1936a6d818ab', $transactionWithImportMeta->importMeta->externalId);
}

/**
* @test
*
Expand Down Expand Up @@ -416,6 +437,34 @@ public static function getRequestProvider(): \Generator
];
}

/**
* @test
*/
public function get_has_import_meta(): void
{
$this->mockClient->addResponse(
new Response(200, body: self::readRawJsonFixture('response/full_entity_with_import_meta')),
);
$transaction = $this->client->transactions->get('txn_01hen7bxc1p8ep4yk7n5jbzk9r');

self::assertNotNull($transaction->importMeta);
self::assertSame('billing_platform', $transaction->importMeta->importedFrom);
self::assertSame('9b95b0b8-e10f-441a-862e-1936a6d818ab', $transaction->importMeta->externalId);
}

/**
* @test
*/
public function get_has_no_import_meta(): void
{
$this->mockClient->addResponse(
new Response(200, body: self::readRawJsonFixture('response/full_entity')),
);
$transaction = $this->client->transactions->get('txn_01hen7bxc1p8ep4yk7n5jbzk9r');

self::assertNull($transaction->importMeta);
}

/**
* @test
*
Expand Down
Loading
Loading