Skip to content

Commit

Permalink
fix: Add test coverage and changelog for nullable payment_method_id (#78
Browse files Browse the repository at this point in the history
)
  • Loading branch information
davidgrayston-paddle authored Sep 18, 2024
1 parent 3935bf3 commit bc1d683
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx
### Fixed

- `PreviewPrice` operation no longer allows empty `items`
- Transaction `payment_method_id` can be `string` or `null`

## [1.1.2] - 2024-08-23

Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Shared/TransactionPaymentAttempt.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function from(array $data): self
{
return new self(
$data['payment_attempt_id'],
$data['payment_method_id'],
$data['payment_method_id'] ?? null,
$data['stored_payment_method_id'],
$data['amount'],
PaymentAttemptStatus::from($data['status']),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@
"type": "card"
},
"payment_attempt_id": "afa07161-601d-4a65-8c1a-6993ae1ae027",
"payment_method_id": "paymtd_01hkm9xwqpbbpr1ksmvg3sx3v1",
"payment_method_id": null,
"stored_payment_method_id": "d3218a38-1cff-44a7-8a47-6a809a5ae9ad"
}
],
Expand Down
15 changes: 15 additions & 0 deletions tests/Functional/Resources/Transactions/TransactionsClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,21 @@ public static function getRequestProvider(): \Generator
];
}

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

$paymentWithPaymentMethodId = $transaction->payments[0];
self::assertSame('paymtd_01hkm9xwqpbbpr1ksmvg3sx3v1', $paymentWithPaymentMethodId->paymentMethodId);

$paymentWithoutPaymentMethodId = $transaction->payments[1];
self::assertNull($paymentWithoutPaymentMethodId->paymentMethodId);
}

/**
* @test
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,48 @@
}
]
},
"payments": [],
"payments": [
{
"payment_attempt_id": "1f8e8302-b6fa-4290-b457-4c201eb3d53f",
"payment_method_id": "paymtd_01hkm9xwqpbbpr1ksmvg3sx3v1",
"stored_payment_method_id": "5f85a637-efa7-4c6b-88ec-9cc05301bb48",
"amount": "40000",
"status": "captured",
"error_code": null,
"method_details": {
"type": "card",
"card": {
"type": "visa",
"last4": "4242",
"expiry_month": 1,
"expiry_year": 2024,
"cardholder_name": "Joe Bloggs"
}
},
"created_at": "2023-08-18T21:13:07.18821Z",
"captured_at": "2023-08-18T21:13:09.477933Z"
},
{
"payment_attempt_id": "1f8e8302-b6fa-4290-b457-4c201eb3d53f",
"payment_method_id": null,
"stored_payment_method_id": "5f85a637-efa7-4c6b-88ec-9cc05301bb48",
"amount": "40000",
"status": "captured",
"error_code": null,
"method_details": {
"type": "card",
"card": {
"type": "visa",
"last4": "4242",
"expiry_month": 1,
"expiry_year": 2024,
"cardholder_name": "Joe Bloggs"
}
},
"created_at": "2023-08-18T21:13:07.18821Z",
"captured_at": "2023-08-18T21:13:09.477933Z"
}
],
"checkout": {
"url": "https://magnificent-entremet-7ae0c6.netlify.app/default/overlay?_ptxn=txn_01hen7bxc1p8ep4yk7n5jbzk9r"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,26 @@
},
"created_at": "2023-08-18T21:13:07.18821Z",
"captured_at": "2023-08-18T21:13:09.477933Z"
},
{
"payment_attempt_id": "1f8e8302-b6fa-4290-b457-4c201eb3d53f",
"payment_method_id": null,
"stored_payment_method_id": "5f85a637-efa7-4c6b-88ec-9cc05301bb48",
"amount": "40000",
"status": "captured",
"error_code": null,
"method_details": {
"type": "card",
"card": {
"type": "visa",
"last4": "4242",
"expiry_month": 1,
"expiry_year": 2024,
"cardholder_name": "Joe Bloggs"
}
},
"created_at": "2023-08-18T21:13:07.18821Z",
"captured_at": "2023-08-18T21:13:09.477933Z"
}
],
"checkout": {
Expand Down

0 comments on commit bc1d683

Please sign in to comment.