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

feat(payments_v2): implement payments capture v2 #6722

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Narayanbhat166
Copy link
Member

@Narayanbhat166 Narayanbhat166 commented Dec 2, 2024

Type of Change

  • New feature

Description

This PR introduces payments capture endpoint for the v2 version.

Motivation and Context

How did you test it?

Create a payment with automatic capture
curl --location 'http://localhost:8080/v2/payments/create-intent' \
--header 'api-key: dev_WvQ9nNM8yudKrDcVqh3FrURJm3HMKU3tmxMFKnlZef9Hkhyxy1r9A89I4s03jO9h' \
--header 'Content-Type: application/json' \
--header 'x-profile-id: pro_MxajZP8J2IgEXmAs0MpY' \
--data '{
    "amount_details": {
        "order_amount": 100,
        "currency": "USD"
    },
    "capture_method":"automatic",
    "authentication_type": "no_three_ds"
}'
  • Response
{
    "id": "12345_pay_0193882e51ac7692905c3279518700eb",
    "status": "requires_payment_method",
    "amount_details": {
        "order_amount": 100,
        "currency": "USD",
        "shipping_cost": null,
        "order_tax_amount": null,
        "skip_external_tax_calculation": "Skip",
        "skip_surcharge_calculation": "Skip",
        "surcharge_amount": null,
        "tax_on_surcharge": null
    },
    "client_secret": "12345_pay_0193882e51ac7692905c3279518700eb_secret_0193882e51ac7692905c3284173ac888",
    "merchant_reference_id": null,
    "routing_algorithm_id": null,
    "capture_method": "automatic",
    "authentication_type": "no_three_ds",
    "billing": null,
    "shipping": null,
    "customer_id": null,
    "customer_present": "Present",
    "description": null,
    "return_url": null,
    "setup_future_usage": "on_session",
    "apply_mit_exemption": "Skip",
    "statement_descriptor": null,
    "order_details": null,
    "allowed_payment_method_types": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "payment_link_enabled": "Skip",
    "payment_link_config": null,
    "request_incremental_authorization": "default",
    "expires_on": "2024-12-02T16:37:37.228Z",
    "frm_metadata": null,
    "request_external_three_ds_authentication": "Skip"
}
Confirm the payment intent
curl --location 'http://localhost:8080/v2/payments/12345_pay_0193882e51ac7692905c3279518700eb/confirm-intent' \
--header 'x-client-secret: 12345_pay_0193882e51ac7692905c3279518700eb_secret_0193882e51ac7692905c3284173ac888' \
--header 'x-profile-id: pro_MxajZP8J2IgEXmAs0MpY' \
--header 'Content-Type: application/json' \
--header 'api-key: pk_dev_538be9702de84258b89c6ac654f5ecb1' \
--data '{
    "payment_method_data": {
        "card": {
            "card_number": "4242424242424242",
            "card_exp_month": "01",
            "card_exp_year": "25",
            "card_holder_name": "John Doe",
            "card_cvc": "100"
        }
    },
    "payment_method_type": "card",
    "payment_method_subtype": "credit"
}'
  • In the response, amount_capturable should be 0 indicating that no amount can be captured further. amount_captured should be equal to the net amount.
{
    "id": "12345_pay_0193882e51ac7692905c3279518700eb",
    "status": "succeeded",
    "amount": {
        "order_amount": 100,
        "currency": "USD",
        "shipping_cost": null,
        "order_tax_amount": null,
        "skip_external_tax_calculation": "Skip",
        "skip_surcharge_calculation": "Skip",
        "surcharge_amount": null,
        "tax_on_surcharge": null,
        "net_amount": 100,
        "amount_to_capture": null,
        "amount_capturable": 0,
        "amount_captured": 100
    },
    "connector": "stripe",
    "client_secret": "12345_pay_0193882e51ac7692905c3279518700eb_secret_0193882e51ac7692905c3284173ac888",
    "created": "2024-12-02T16:22:37.228Z",
    "payment_method_data": null,
    "payment_method_type": "card",
    "payment_method_subtype": "credit",
    "next_action": null,
    "connector_transaction_id": "pi_3QRcOZD5R7gDAGff1DNcLrku",
    "connector_reference_id": null,
    "merchant_connector_id": "mca_viTlEW768QtaKIyYYGjl",
    "browser_info": null,
    "error": null
}
Create a payment with manual capture
curl --location 'http://localhost:8080/v2/payments/create-intent' \
--header 'api-key: dev_WvQ9nNM8yudKrDcVqh3FrURJm3HMKU3tmxMFKnlZef9Hkhyxy1r9A89I4s03jO9h' \
--header 'Content-Type: application/json' \
--header 'x-profile-id: pro_MxajZP8J2IgEXmAs0MpY' \
--data '{
    "amount_details": {
        "order_amount": 100,
        "currency": "USD"
    },
    "capture_method":"manual",
    "authentication_type": "no_three_ds"
}'
Confirm the payment intent
curl --location 'http://localhost:8080/v2/payments/create-intent' \
--header 'api-key: dev_WvQ9nNM8yudKrDcVqh3FrURJm3HMKU3tmxMFKnlZef9Hkhyxy1r9A89I4s03jO9h' \
--header 'Content-Type: application/json' \
--header 'x-profile-id: pro_MxajZP8J2IgEXmAs0MpY' \
--data '{
    "amount_details": {
        "order_amount": 100,
        "currency": "USD"
    },
    "capture_method":"manual",
    "authentication_type": "no_three_ds"
}'

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

Copy link

semanticdiff-com bot commented Dec 2, 2024

@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant