hyperswitch
hyperswitch copied to clipboard
feat(Connectors): add mandate validation for auth flow
Type of Change
- [ ] Bugfix
- [x] New feature
- [x] Enhancement
- [ ] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD
Description
This PR validated mandate payment. When we try to create a mandate payment with a specific connector's payment method that don't implement mandate,
we throw a not supported error.
Note: if the payment method itself is not implemented for the connector, we throw a payment method not supported error and not the mandate not supported error
How did you test it?
- Create a mandate payment with a payment method of a specific connector that implements mandate for the pm. eg- Stripe card mandates
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: {{}}' \
--data-raw '{
"amount": 120,
"currency": "USD",
"confirm": true,
"capture_method": "automatic",
"capture_on": "2022-09-10T10:11:12Z",
"customer_id": "A",
"email": "[email protected]",
"name": "John Doe",
"phone": "999999999",
"phone_country_code": "+65",
"description": "Its my first payment request",
"authentication_type": "three_ds",
"return_url": "https://google.com",
"billing": {
"address": {
"line1": "1467",
"line2": "Harrison Street",
"line3": "Harrison Street",
"city": "San Fransico",
"state": "California",
"zip": "94122",
"country": "US",
"first_name": "John",
"last_name": "Doe"
}
},
"browser_info": {
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
"accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"language": "nl-NL",
"color_depth": 24,
"screen_height": 723,
"screen_width": 1536,
"time_zone": 0,
"java_enabled": true,
"java_script_enabled": true,
"ip_address": "13.232.74.226"
},
"shipping": {
"address": {
"line1": "1467",
"line2": "Harrison Street",
"line3": "Harrison Street",
"city": "San Fransico",
"state": "California",
"zip": "94122",
"country": "IN",
"first_name": "John",
"last_name": "Doe"
}
},
"statement_descriptor_name": "joseph",
"statement_descriptor_suffix": "JS",
"payment_method": "card",
"payment_method_data": {
"card": {
"card_number": "4100000000000019",
"card_exp_month": "01",
"card_exp_year": "2026",
"card_holder_name": "Joseph Doe",
"card_cvc": "124"
}
},
"metadata": {
"city": "NY",
"unit": "245",
"account_name": "transaction_processing"
},
"payment_type": "setup_mandate",
"setup_future_usage": "off_session",
"mandate_data": {
"customer_acceptance": {
"acceptance_type": "offline",
"accepted_at": "1963-05-03T04:07:52.723Z",
"online": {
"ip_address": "13.232.74.226",
"user_agent": "amet irure esse"
}
},
"mandate_type": {
"multi_use": {
"amount": 799,
"currency": "USD"
}
}
}
}'
Response
{
"payment_id": "pay_5ilW47B59zJrkPhPMQty",
"merchant_id": "merchant_1710418107",
"status": "requires_customer_action",
"amount": 120,
"net_amount": 120,
"amount_capturable": 120,
"amount_received": null,
"connector": "stripe",
"client_secret": "pay_5ilW47B59zJrkPhPMQty_secret_n8rFyve1a9oLmAry7a5C",
"created": "2024-03-14T12:08:40.700Z",
"currency": "USD",
"customer_id": "A",
"description": "Its my first payment request",
"refunds": null,
"disputes": null,
"mandate_id": "man_bLL0elxZ7SnB1XULGZLs",
"mandate_data": {
"update_mandate_id": null,
"customer_acceptance": {
"acceptance_type": "offline",
"accepted_at": "1963-05-03T04:07:52.723Z",
"online": {
"ip_address": "13.232.74.226",
"user_agent": "amet irure esse"
}
},
"mandate_type": {
"multi_use": {
"amount": 799,
"currency": "USD",
"start_date": null,
"end_date": null,
"metadata": null
}
}
},
"setup_future_usage": "off_session",
"off_session": null,
"capture_on": null,
"capture_method": "automatic",
"payment_method": "card",
"payment_method_data": {
"card": {
"last4": "0019",
"card_type": null,
"card_network": null,
"card_issuer": null,
"card_issuing_country": null,
"card_isin": "410000",
"card_extended_bin": "41000000",
"card_exp_month": "01",
"card_exp_year": "2026",
"card_holder_name": "Joseph Doe"
},
"billing": null
},
"payment_token": null,
"shipping": {
"address": {
"city": "San Fransico",
"country": "IN",
"line1": "1467",
"line2": "Harrison Street",
"line3": "Harrison Street",
"zip": "94122",
"state": "California",
"first_name": "John",
"last_name": "Doe"
},
"phone": {
"number": null,
"country_code": null
},
"email": null
},
"billing": {
"address": {
"city": "San Fransico",
"country": "US",
"line1": "1467",
"line2": "Harrison Street",
"line3": "Harrison Street",
"zip": "94122",
"state": "California",
"first_name": "John",
"last_name": "Doe"
},
"phone": {
"number": null,
"country_code": null
},
"email": null
},
"order_details": null,
"email": "[email protected]",
"name": "John Doe",
"phone": "999999999",
"return_url": "https://google.com/",
"authentication_type": "three_ds",
"statement_descriptor_name": "joseph",
"statement_descriptor_suffix": "JS",
"next_action": {
"type": "redirect_to_url",
"redirect_to_url": "http://localhost:8080/payments/redirect/pay_5ilW47B59zJrkPhPMQty/merchant_1710418107/pay_5ilW47B59zJrkPhPMQty_1"
},
"cancellation_reason": null,
"error_code": null,
"error_message": null,
"unified_code": null,
"unified_message": null,
"payment_experience": null,
"payment_method_type": null,
"connector_label": null,
"business_country": null,
"business_label": "default",
"business_sub_label": null,
"allowed_payment_method_types": null,
"ephemeral_key": {
"customer_id": "A",
"created_at": 1710418120,
"expires": 1710421720,
"secret": "epk_6a6b17981d0c40b1a204a092e9b86d74"
},
"manual_retry_allowed": null,
"connector_transaction_id": "seti_1OuD5SD5R7gDAGffz5fKId48",
"frm_message": null,
"metadata": {
"city": "NY",
"unit": "245",
"account_name": "transaction_processing"
},
"connector_metadata": null,
"feature_metadata": null,
"reference_id": "seti_1OuD5SD5R7gDAGffz5fKId48",
"payment_link": null,
"profile_id": "pro_iu31vSMMva13ArEY2UpS",
"surcharge_details": null,
"attempt_count": 1,
"merchant_decision": null,
"merchant_connector_id": "mca_VB46wUk1aT5tPdtIKZyQ",
"incremental_authorization_allowed": null,
"authorization_count": null,
"incremental_authorizations": null,
"external_authentication_details": null,
"request_external_3ds_authentication": null,
"expires_on": "2024-03-14T12:23:40.700Z",
"fingerprint": null,
"payment_method_id": "pm_6MT8sD3htHAXuNJ9lXxE",
"payment_method_status": "processing"
}
2.Create a mandate payment with a payment method of a specific connector that do not implement mandate for the pm. eg- Stripe alipay mandates
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key:{{}}' \
--data-raw '{
"amount": 6540,
"currency": "USD",
"confirm": true,
"capture_method": "automatic",
"capture_on": "2022-09-10T10:11:12Z",
"amount_to_capture": 6540,
"customer_id": "StripeCustomer",
"email": "[email protected]",
"name": "John Doe",
"phone": "999999999",
"phone_country_code": "+1",
"description": "Its my first payment request",
"authentication_type": "no_three_ds",
"return_url": "https://google.com",
"payment_method": "wallet",
"payment_method_type": "ali_pay",
"payment_method_data": {
"wallet": {
"ali_pay_redirect": {}
}
},
"billing": {
"address": {
"line1": "1467",
"line2": "Harrison Street",
"line3": "Harrison Street",
"city": "San Fransico",
"state": "California",
"zip": "94122",
"country": "US",
"first_name": "joseph",
"last_name": "Doe"
},
"phone": {
"number": "8056594427",
"country_code": "+91"
}
},
"shipping": {
"address": {
"line1": "1467",
"line2": "Harrison Street",
"line3": "Harrison Street",
"city": "San Fransico",
"state": "California",
"zip": "94122",
"country": "US",
"first_name": "joseph",
"last_name": "Doe"
},
"phone": {
"number": "8056594427",
"country_code": "+91"
}
},
"statement_descriptor_name": "joseph",
"statement_descriptor_suffix": "JS",
"metadata": {
"udf1": "value1",
"new_customer": "true",
"login_date": "2019-09-10T10:11:12Z"
},
"setup_future_usage": "off_session",
"mandate_data": {
"customer_acceptance": {
"acceptance_type": "offline",
"accepted_at": "1963-05-03T04:07:52.723Z",
"online": {
"ip_address": "13.232.74.226",
"user_agent": "amet irure esse"
}
},
"mandate_type": {
"multi_use": {
"amount": 799,
"currency": "USD"
}
}
}
}'
Response: http_status:400 Bad Request
{
"error": {
"type": "invalid_request",
"message": "Payment method type not supported",
"code": "HE_03",
"reason": "ali_pay mandate payment is not supported by stripe"
}
}
Impacted Connectors
All payment connectors
Checklist
- [x] I formatted the code
cargo +nightly fmt --all - [x] I addressed lints thrown by
cargo clippy - [x] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible
- [ ] I added a CHANGELOG entry if applicable