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

[Backend Receipts] Network layer for receipt endpoint #11837

Merged
merged 3 commits into from Jan 30, 2024

Conversation

iamgabrielma
Copy link
Contributor

@iamgabrielma iamgabrielma commented Jan 29, 2024

Closes: #11825

Description

This PR adds the necessary network layer for the new wc/v3/orders/<order-id>/receipt endpoint, part of the Backend Receipts project ( pfoUAQ-b9-p2 ).

The endpoint has not yet landed in WooCommerce core, but it's being worked on a development branch: woocommerce/woocommerce#43502 using WooCommerce Version 8.6.0-dev-7625495467-gf50cc6b

From the app, we intend to submit a POST request to the endpoint, such as:

curl -X POST "https://mywootestingstore.mystagingwebsite.com/wp-json/wc/v3/orders/<order-id>/receipt?<consumer-key>&consumer_secret=<consumer-secret>"

And expect a response that contains a receipt_url with an URL to the order receipt, as well as an expiration_date.

{
    "receipt_url":"https:\/\/mywootestingstore.com\/wc\/file\/transient\/7e811be40195b17f82604592ed26b694868807",
    "expiration_date":"2024-01-27"
}

Testing instructions

Still not being used. Unit tests should pass.

Base automatically changed from issue/11824-receipts-backend-feature-flag to trunk January 29, 2024 07:30
@iamgabrielma iamgabrielma added type: task An internally driven task. feature: order details Related to order details. feature: mobile payments Related to mobile payments / card present payments / Woo Payments. labels Jan 29, 2024
@iamgabrielma iamgabrielma added this to the 17.2 milestone Jan 29, 2024
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jan 29, 2024

WooCommerce iOS📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr11837-6017163
Version17.1
Bundle IDcom.automattic.alpha.woocommerce
Commit6017163
App Center BuildWooCommerce - Prototype Builds #7820
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@iamgabrielma iamgabrielma marked this pull request as ready for review January 29, 2024 10:14
///
public func retrieveReceipt(siteID: Int64,
orderID: Int64,
forceRegenerate: Bool = true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the time being we intend to always force receipt regeneration when calling the endpoint, this might change later (specially if we end calling it upon view load or refresh control), but for the moment we'll pass true as default parameter.

import Foundation

public struct Receipt: Decodable {
public let receiptURL: String
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'm 50/50 about renaming this parameter from receiptURL to receiptURLString or similar. I went ahead with receiptURL for consistency with the API, but I can see the case for being consistent with the data type on the client instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose the client will need to create URL object from it? If we always need to create URL on the client maybe we can do it when initializing Receipt. Or we have receiptURLString and have a computed property var receiptURL: URL??

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, at some point we'll create the URL object from it, but from my exploration we might not need it until the last moment in the presentation layer when we're actually invoking the WKWebView initializer with an URL(string: <url-goes-here>) .

Since we also won't do any validation regarding the contents of the URL through the business layer, the rest of the app shouldn't care if this is a valid URL or not, the web view will either return a receipt or a 404/other messages when needed, so I think I'm happy to keep it as a simple String while the data flows through the app, but the model can also map this to a different type as needed later on.

@iamgabrielma
Copy link
Contributor Author

Only one reviewer is needed 🙇

@iamgabrielma iamgabrielma merged commit 9b0eefc into trunk Jan 30, 2024
24 of 25 checks passed
@iamgabrielma iamgabrielma deleted the issue/11825-receipts-backend-add-endpoint branch January 30, 2024 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: mobile payments Related to mobile payments / card present payments / Woo Payments. feature: order details Related to order details. type: task An internally driven task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Backend Receipts] Network layer for receipts endpoint
3 participants