Skip to content

feat(order): add AP dataclasses, docs and example for automatic payments (IXE-679)#115

Merged
danielalfarourrea merged 12 commits into
masterfrom
feature/orders_IXE_679
May 29, 2026
Merged

feat(order): add AP dataclasses, docs and example for automatic payments (IXE-679)#115
danielalfarourrea merged 12 commits into
masterfrom
feature/orders_IXE_679

Conversation

@danielalfarourrea
Copy link
Copy Markdown
Contributor

Summary

New dataclasses for the Automatic Payments flow — optional typed helpers; the existing dict-based API is unchanged.

New files (mercadopago/resources/):

  • order_stored_credential.pyOrderStoredCredential — includes prev_transaction_ref, required from the second recurring charge onwards.
  • order_automatic_payments.pyOrderAutomaticPayments
  • order_subscription_data.pyOrderSubscriptionData + OrderSubscriptionSequence + OrderInvoicePeriod
  • order_integration_data.pyOrderIntegrationData + OrderSponsor

Updated:

  • order.py → class-level docstring documenting all AP dict keys with types.

New example:

  • examples/order/create_order_automatic_payment.py → full AP flow: first payment (first_payment=True) and recurring charge (prev_transaction_ref=prev_tx_id).

How to use

import dataclasses
from mercadopago.resources.order_stored_credential import OrderStoredCredential

# Build typed object
sc = OrderStoredCredential(
    payment_initiator="merchant",
    reason="recurring",
    first_payment=False,
    prev_transaction_ref="TX-001-2026"
)

# Convert to dict and pass to SDK
sdk.order().create({
    "transactions": {"payments": [{
        "stored_credential": dataclasses.asdict(sc)
    }]}
})

Both approaches (plain dict and dataclass) produce identical JSON. The dataclass is optional.

Context

Part of IXE-679: fields required for the Automatic Payments flow in the Orders API were missing from the public SDKs. Companion PRs exist for Java, Go, .NET, Node.js, PHP and Ruby.

Test plan

  • python -m py_compile on all new files — OK
  • Integration tests (not run per policy — require ACCESS_TOKEN)

Generated with Claude Code

danielalfarourrea and others added 12 commits May 27, 2026 13:44
…change and refresh

Enables marketplace and platform integrations to operate on behalf of
other sellers via the OAuth 2.0 authorization code flow.

Operations:
- get_authorization_url(): builds https://auth.mercadopago.com/authorization?...
- create(): POST /oauth/token (exchange authorization code for access token)
- refresh(): POST /oauth/token (refresh expired token)

Ref: sdk-php/src/MercadoPago/Client/OAuth/OAuthClient.php
- test_oauth: validates URL builder output and ValueError on non-dict input
- test_point: validates HTTP response range and ValueError on non-dict input
- test_invoice: validates HTTP response range for search operation
- examples/oauth/create_token.py: authorization URL + token exchange flow
- examples/point/create_payment_intent.py: list devices, create and get payment intent
- examples/invoice/get_invoice.py: search invoices by preapproval_id and get by ID
- resources/__init__.py: add Invoice, OAuth, Point imports and __all__ entries
- sdk.py: add Invoice, OAuth, Point imports and factory methods
  (sdk.invoice(), sdk.oauth(), sdk.point())
New features in this release:
- OAuth: authorization URL, token exchange and refresh (POST /oauth/token)
- Point: payment intents and device management (/point/integration-api/...)
- Invoice: get and search subscription invoices (GET /authorized_payments)

Note: version bump in pyproject.toml and config.py requires approval before merge.
New features in this release:
- OAuth: authorization URL, token exchange and refresh (POST /oauth/token)
- Point: payment intents and device management (/point/integration-api/...)
- Invoice: get and search subscription invoices (GET /authorized_payments)
…nts (IXE-679)

Add typed helpers and documentation for the Automatic Payments flow in
the Orders API. The SDK remains dict-based; these additions are optional
conveniences for developers who prefer typed objects.

New dataclasses (mercadopago/resources/):
- order_stored_credential.py: OrderStoredCredential — includes the new
  prev_transaction_ref field, required from the second recurring charge
  onwards to link the payment to the original card-network authorization.
- order_automatic_payments.py: OrderAutomaticPayments — payment_profile_id,
  retries, schedule_date, due_date.
- order_subscription_data.py: OrderSubscriptionData, OrderSubscriptionSequence,
  OrderInvoicePeriod — full subscription billing cycle support.
- order_integration_data.py: OrderIntegrationData, OrderSponsor — integration
  metadata for marketplace and platform identification.

Updated:
- order.py: added class-level docstring documenting all AP-supported dict
  keys with types (stored_credential, automatic_payments, subscription_data,
  integration_data).

New example:
- examples/order/create_order_automatic_payment.py: full AP flow showing
  first payment (first_payment=True) and recurring charge
  (prev_transaction_ref=prev_tx_id) using dataclasses.asdict().

No break changes: existing dict-based API is unmodified. Developers use
dataclasses.asdict() to convert typed objects to the dict the SDK expects.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Remove the unused 'field' import from dataclasses in order_stored_credential.py
and order_subscription_data.py to resolve pylint W0611 warnings.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@danielalfarourrea danielalfarourrea merged commit 226dc66 into master May 29, 2026
1 of 4 checks passed
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

Successfully merging this pull request may close these issues.

1 participant