Skip to content

Implement Subscriptions #364

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

Open
wants to merge 7 commits into
base: 9.3.x
Choose a base branch
from

Conversation

alexstewartja
Copy link
Contributor

@alexstewartja alexstewartja commented Mar 8, 2025

Core Changes

  • Created Subscription related models and API client
  • Integrated subscription client actions into the main Client class
  • Added functional Subscription tests

Auxiliary Changes

  • Added SettlementStatus class
  • Added a convenience const to Env class for BitPay's datetime format
  • Updated dependencies (symfony/console)

+ Created subscription related models
+ Integrated subscription actions into the main Client class
+ Added a convenience const to Env class for BitPay's datetime format
+ Added functional Subscription tests
+ Updated dependencies
+ Created subscription related models
+ Integrated subscription actions into the main Client class
+ Added a convenience const to Env class for BitPay's datetime format
+ Added functional Subscription tests
+ Updated dependencies
@alexstewartja alexstewartja marked this pull request as ready for review March 10, 2025 11:41
@bobbrodie
Copy link
Collaborator

Thank you for the submission! We'll take a look and get this scheduled.

@bobbrodie bobbrodie added this to the v9.3.0 milestone Mar 31, 2025
@bobbrodie bobbrodie moved this to Todo in SDKs & Plugins Apr 1, 2025
@bobbrodie bobbrodie moved this from Todo to Under Review in SDKs & Plugins Apr 1, 2025
@bobbrodie bobbrodie changed the base branch from 9.2.x to 9.3.x May 28, 2025 00:54
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we can remove this file in favor of src/BitPaySDK/Model/Bill/Bill.php.

Copy link
Collaborator

@bobbrodie bobbrodie May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexstewartja I've taken a deeper look and I see that Bill and BillData won't be 1:1, however there's a lot of overlap. It could be worth considering extracting certain types to reduce duplication.

For example, they both have:

  • currency
  • email
  • items (which are Bill/Item)
  • number
  • name
  • address1
  • address2
  • city
  • state
  • zip
  • country
  • cc
  • phone
  • dueDate
  • passProcessingFee

We could think about extracting these into an class such as CoreBill and then extending it for Bill and using it as a type in Subscription for $billData. I'm not sure that it's worth it, but wanted to see what folks think.

If that won't work, it's OK, just thinking it through and sharing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I'm all for composition and adherence to DRY principles. We should definitely abstract away those repetitive fields. I'll put your suggestion into action later today.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @bobbrodie, there is no need for another class. All missing fields can be added to Bill\Bill or you can create a class that extends it to eliminate duplicates.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can use src/BitPaySDK/Model/Bill/Bill.php, we'll carry the reference to src/BitPaySDK/Model/Bill/Item.php.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexstewartja to clarify the above, Subscription/Item carries the same properties as Bill/Item, and fundamentally represent the same thing, so even if we don't extract core bill properties and extend, I think we can still consider using Bill/Item instead of Subscription/Item.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I support using Bill\Item instead of a separate class.

{
protected ?string $id = null;
protected ?string $status = null;
protected BillData $billData;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's consider src/BitPaySDK/Model/Bill/Bill.php

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get that they appear identical, but if this package is to be a pure abstraction over the API endpoints, then we have to account for the subtle differences in the structure/shape of Subscriptions vs Bills.

For example, the Create a Bill response data is unwrapped and relatively one-dimensional. On the other hand the Create a Subscription response data is wrapped in the billData field, one level deep.

Copy link
Collaborator

@bobbrodie bobbrodie May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I'm sorry for not clarifying this a bit, @alexstewartja. This comment was for line 22. Currently, $billData is typed to BillData. We could keep $billData of course, but maybe have it typed to a new type with just the core bill fields that are shared between Bill and Subscription. I think there are ~15 common fields.

Since a subscription is just a recurring bill, so BillData represents a Bill, albeit with fewer properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks for the clarification. I'll create a base/core model then inherit/extend from it to implement the specifics of Subscriptions

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @bobbrodie, there is no need for another class. All missing fields can be added to Bill\Bill or you can create a class that extends it to eliminate duplicates.

$this->number = $number;
$this->currency = $currency ?: Currency::USD;
$this->email = $email;
$this->setEmailBill();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a good idea to force emailBill in the constructor? Shouldn't this be controlled by the developer?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I support using Bill\Item instead of a separate class.

@@ -576,7 +578,7 @@ public function getBill(string $billId, string $facade = Facade::MERCHANT, bool
*
* @see https://developer.bitpay.com/reference/retrieve-bills-by-status Retrieve Bills by Status
*
* @param string|null The status to filter the bills.
* @param $status string|null The status to filter the bills.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name should be after the type.

*
* @see https://developer.bitpay.com/reference/retrieve-a-subscription Retrieve a Subscription
*
* @param $subscriptionId string The ID of the subscription to retrieve.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

*
* @see https://developer.bitpay.com/reference/retrieve-subscriptions-by-status Retrieve Subscriptions by Status
*
* @param $status string|null The status on which to filter the subscriptions.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect order of type and var name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Under Review
Development

Successfully merging this pull request may close these issues.

3 participants