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

TransactionTimePeriod - should it be public constructor? #60

Closed
dutypro opened this issue Aug 23, 2024 · 2 comments
Closed

TransactionTimePeriod - should it be public constructor? #60

dutypro opened this issue Aug 23, 2024 · 2 comments
Assignees

Comments

@dutypro
Copy link
Contributor

dutypro commented Aug 23, 2024

Describe the bug

I'm trying to create a new transaction using the SDK but I keep running in to an error:

{
    "field": "billing_period.starts_at",
    "error": "Invalid type. Expected: string, given: object"
},
{
    "field": "billing_period.ends_at",
    "error": "Invalid type. Expected: string, given: object"
}

Here is my transaction logic:

$transactionData = new CreateTransaction(
    items: $items,
    customerId: $this->transaction->customer->paddle_id ?? null,
    addressId: $this->transaction->address->paddle_id ?? null,
    businessId: $this->transaction->business->paddle_id ?? null,
    currencyCode: new CurrencyCode(
        $this->transaction->currency_code
    ),
    collectionMode: new CollectionMode(
        $this->transaction->collection_mode
    ),
    discountId: $this->transaction->discount->paddle_id ?? null,
    billingDetails: new BillingDetails(
        enableCheckout: $this->transaction->enable_checkout,
        paymentTerms: new TimePeriod(
            interval: Interval::from(
                $this->transaction->terms_interval
            ),
            frequency: $this->transaction->terms_frequency,
        ),
        purchaseOrderNumber: $this->transaction->purchase_order_number ?? null,
        additionalInformation: $this->transaction->additional_information ?? '',
    ),
    billingPeriod: TransactionTimePeriod::from([
        'starts_at' => new DateTimeImmutable($this->transaction->starts_at),
        'ends_at' => new DateTimeImmutable($this->transaction->ends_at)
    ]),
    customData: new CustomData([
        'transaction_id' => $this->transaction->id,
        'customer_id' => $this->transaction->customer->id,
    ])
);

// Log the serialized data
Log::info('Transaction Data: ' . json_encode($transactionData));

And the output:

{
    "items": [
        {
            "quantity": 1,
            "price_id": "pri_abc"
        }
    ],
    "customer_id": "ctm_abc",
    "address_id": "add_abc",
    "business_id": "biz_abc",
    "custom_data": {
        "transaction_id": 2,
        "customer_id": 1
    },
    "currency_code": "USD",
    "collection_mode": "manual",
    "discount_id": null,
    "billing_details": {
        "enableCheckout": true,
        "paymentTerms": {
            "interval": "day",
            "frequency": 28
        },
        "purchaseOrderNumber": "TEST-PO-123",
        "additionalInformation": ""
    },
    "billing_period": {
        "startsAt": {
            "date": "2024-08-23 10:07:00.000000",
            "timezone_type": 2,
            "timezone": "Z"
        },
        "endsAt": {
            "date": "2025-08-23 10:07:00.000000",
            "timezone_type": 2,
            "timezone": "Z"
        }
    }
}

I could be completely missing something but I've trawled through the classes and can't get my head around it.

Steps to reproduce

  1. Create a new CreateTransaction method.
  2. Submit via SDK

Expected behavior

I would expect to be able to access the billingPeriod params like so:

billingPeriod: new TransactionTimePeriod(
    startsAt: $this->transaction->starts_at,
    endsAt: $this->transaction->ends_at
)

But I can't because the constructor of the TransactionTimePeriod class is private.

Instead, I have to use the ::from method which causes the serialization error.

I think the constructor on the TransactionTimePeriod class should be public and if you're in agreement I can submit a PR.

Code snippets

No response

PHP version

8.3.10

SDK version

1.1.1

API version

1

Additional context

If there's an intended usage pattern that I may be missing or another recommended approach to avoid this issue, please let me know.

@vifer
Copy link
Contributor

vifer commented Aug 23, 2024

Hey @dutypro I think you are correct, thank you so much for opening a PR to fix this, I will approve it and bump the version ❤️

@vifer
Copy link
Contributor

vifer commented Aug 23, 2024

@dutypro closing this issue, changes got released see v.1.1.2 release, thanks again for your contribution.

@vifer vifer closed this as completed Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants