Skip to content

Conversation

Sarthak1799
Copy link
Contributor

@Sarthak1799 Sarthak1799 commented Jun 13, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

This PR enables -

  • Ephemeral key auth for customer's pm list
  • Ephemeral key auth for delete payment method

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

How did you test it?

  1. Save a card for a customer
  2. Create Ephemeral key for that customer
curl --location --request POST 'http://localhost:8080/ephemeral_keys' \
--header 'Content-Type: application/json' \
--header 'api-key: dev_cHN6hMdCFUUrNWjYSxnwhiuMsg83rXTX9jBmtHmCL6sq9a43PswY304MSt3a9blR' \
--data-raw '{
    "customer_id": "cus_q1KVr57JhvRlVHToTKkY"
}'

Response -

{
    "id": "eki_DuTISISBl1O0MAyczMQ8",
    "merchant_id": "sarthak1",
    "customer_id": "cus_grCxh6TyR6uepXyc6p7q",
    "created_at": 1718270809,
    "expires": 1718274409,
    "secret": "epk_67d4e3b46c49402badcbff4901cfef67"
}
  1. Use the Ephemeral key secret to call customer's pm list
curl --location --request GET 'http://localhost:8080/customers/payment_methods' \
--header 'Accept: application/json' \
--header 'api-key: epk_be243219006647c69cdd7111d490d79a'

Response -

{
    "customer_payment_methods": [
        {
            "payment_token": "token_9OtU08A46TOZcmfislqy",
            "payment_method_id": "pm_RPkRCYXKIWZFj0Qr36E9",
            "customer_id": "Some_cust1",
            "payment_method": "card",
            "payment_method_type": null,
            "payment_method_issuer": null,
            "payment_method_issuer_code": null,
            "recurring_enabled": false,
            "installment_payment_enabled": false,
            "payment_experience": [
                "redirect_to_url"
            ],
            "card": {
                "scheme": null,
                "issuer_country": null,
                "last4_digits": "4242",
                "expiry_month": "10",
                "expiry_year": "2025",
                "card_token": null,
                "card_holder_name": "joseph Doe",
                "card_fingerprint": null,
                "nick_name": null,
                "card_network": null,
                "card_isin": "424242",
                "card_issuer": null,
                "card_type": null,
                "saved_to_locker": true
            },
            "metadata": null,
            "created": "2024-06-13T09:59:16.717Z",
            "bank": null,
            "surcharge_details": null,
            "requires_cvv": true,
            "last_used_at": "2024-06-13T09:59:16.717Z",
            "default_payment_method_set": true,
            "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": "8056594427",
                    "country_code": "+91"
                },
                "email": null
            }
        }
    ],
    "is_guest_customer": null
}
  1. Separate flow, Delete a PM using Ephemeral key
curl --location --request DELETE 'http://localhost:8080/payment_methods/pm_RPkRCYXKIWZFj0Qr36E9' \
--header 'Accept: application/json' \
--header 'api-key: epk_be243219006647c69cdd7111d490d79a'

Response -

{
    "payment_method_id": "pm_RPkRCYXKIWZFj0Qr36E9",
    "deleted": true
}

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

@Sarthak1799 Sarthak1799 added C-feature Category: Feature request or enhancement A-payment-methods Area: Payment Methods labels Jun 13, 2024
@Sarthak1799 Sarthak1799 self-assigned this Jun 13, 2024
@Sarthak1799 Sarthak1799 requested review from a team as code owners June 13, 2024 10:38
@Sarthak1799 Sarthak1799 linked an issue Jun 13, 2024 that may be closed by this pull request
2 tasks
vspecky
vspecky previously approved these changes Jun 13, 2024
Copy link
Contributor

@racnan racnan left a comment

Choose a reason for hiding this comment

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

Authentication can be done in a neater way.

Comment on lines +3089 to +3099
let auth_cust = if let Some(key) = ephemeral_api_key {
let key = state
.store()
.get_ephemeral_key(key)
.await
.change_context(errors::ApiErrorResponse::Unauthorized)?;

Some(key.customer_id.clone())
} else {
None
};
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be done in authenticationAndFetch function.
we should refrain from passing keys in core functions.

@likhinbopanna likhinbopanna added this pull request to the merge queue Jun 13, 2024
Merged via the queue into main with commit ad7886a Jun 13, 2024
@likhinbopanna likhinbopanna deleted the pm-ephemeral-auth branch June 13, 2024 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-payment-methods Area: Payment Methods C-feature Category: Feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Use Ephemeral auth for Customer PM list and PM delete APIs
5 participants