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

fix(router): Payment link api contract change #2975

Merged
merged 86 commits into from
Jan 8, 2024

Conversation

sahkal
Copy link
Contributor

@sahkal sahkal commented Nov 24, 2023

Type of Change

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

Description

Changed payment link api-contract to more optimised api-contract for merchants to use.

From

"payment_link_object": {
        "link_expiry": "2025-10-09T16:23:10Z", 
        "merchant_custom_domain_name": null, 
        "custom_merchant_name": null,
        "payment_link_config": {
            "merchant_logo": "https://i.pinimg.com/736x/4d/83/5c/4d835ca8aafbbb15f84d07d926fda473.jpg",
            "color_scheme": {
                "background_primary_color": "#FED5BF",
                "sdk_theme": "#FED5BF"
            }
        }
    }

To

 "session_expiry": 1,
 "payment_link":true,
"payment_link_config": {
        "theme": null,
        "logo" : "https://i.pinimg.com/736x/4d/83/5c/4d835ca8aafbbb15f84d07d926fda473.jpg",
        "seller_name": "sahkal"
    } -- payment Create
  
  
"session_expiry": 1,
"payment_link_config": {
        "theme": null,
        "logo" : "https://i.pinimg.com/736x/4d/83/5c/4d835ca8aafbbb15f84d07d926fda473.jpg",
        "seller_name": "sahkal"
        "domain_name": "pay.amazon"
    }  -- business create
 

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?

Screenshot 2023-11-24 at 3 32 11 PM

Test Case

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_jpG5VqK8K8wsVuXJLsfG4CBrzCxRXI4rpO3lPMyk7EJXKsUDurIaZ3UrVSlH0hbI' \
--data '{
    "amount": 200,
    "currency": "USD",
    "confirm": false,
    "customer_id": "sahkal",
    "return_url": "https://google.com",
    "description": "For selling Tea",
    "order_details": [
        {
            "product_name": "Tea",
            "quantity": 1,
            "amount": 100,
            "product_img_link": null
        },
        {
            "product_name": "Tea",
            "quantity": 1,
            "amount": 100,
            "product_img_link": "https://thumbs.dreamstime.com/b/indian-tea-spices-masala-chai-33827904.jpg"
        }
    ],
    "payment_link": true,
    "session_expiry": 4325,
    "payment_link_config": {
        "theme": null,
        "logo" : "https://i.pinimg.com/736x/4d/83/5c/4d835ca8aafbbb15f84d07d926fda473.jpg",
        "seller_name": "sahkal"
    }
}'
Screenshot 2023-12-25 at 9 59 07 PM

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
  • I added a CHANGELOG entry if applicable

@sahkal sahkal added A-core Area: Core flows S-waiting-on-review Status: This PR has been implemented and needs to be reviewed M-database-changes Metadata: This PR involves database schema changes M-api-contract-changes Metadata: This PR involves API contract changes labels Nov 24, 2023
@sahkal sahkal added this to the November 2023 Release milestone Nov 24, 2023
@sahkal sahkal self-assigned this Nov 24, 2023
@sahkal sahkal requested review from a team as code owners November 24, 2023 10:03
@sahkal sahkal requested a review from a team as a code owner November 24, 2023 13:16
let merchant_surcharge_configs =
if let Some((attempt, payment_intent)) = payment_attempt.as_ref().zip(payment_intent) {
if let Some((payment_attempt, payment_intent, business_profile)) =
combine_options!(payment_attempt_ref, payment_intent, business_profile)
Copy link
Member

@Narayanbhat166 Narayanbhat166 Jan 5, 2024

Choose a reason for hiding this comment

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

isn't this what zip does?
You can do something like

Suggested change
combine_options!(payment_attempt_ref, payment_intent, business_profile)
payment_attempt_ref.zip(payment_intent).zip(business_profile).map(|(a,b),c| (a,b,c))

Copy link
Contributor

Choose a reason for hiding this comment

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

when it comes to zipping 3 or more options, we would need to make use of nested tuples. With this macro, only single tuple is needed. looks cleaner.
With zip: if let Some(((value1, value2), value3)) = opt1.zip(opt2).zip(opt3) .
With combine_options: if let Some((value1, value2, value3)) = combine_options!(opt1, opt2, opt3)

.find_payment_link_by_payment_link_id(&payment_link_id)
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentLinkNotFound)?;

let status = check_payment_link_status(payment_link_object.fulfilment_time);
let status = check_payment_link_status(payment_link_config.fulfilment_time);
Copy link
Member

Choose a reason for hiding this comment

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

what if this is none, use unwrap_or and then pass the default value. I see that session_expiry is being already calculated below, use the same value instead of checking this.

};

let theme = payment_create_link_config
.clone()
Copy link
Member

Choose a reason for hiding this comment

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

use as_ref here and then clone the inner value. You can do the same for a lot of clones below. Fight the compiler

let business_profile = if let Some(business_profile) =
core_utils::validate_and_get_business_profile(
db,
request.profile_id.as_ref(),
Copy link
Member

Choose a reason for hiding this comment

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

pass Some(profile_id)

Narayanbhat166
Narayanbhat166 previously approved these changes Jan 8, 2024
@likhinbopanna likhinbopanna disabled auto-merge January 8, 2024 11:20
@sahkal sahkal requested a review from racnan January 8, 2024 11:26
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Jan 8, 2024
Merged via the queue into main with commit 3cd7496 Jan 8, 2024
9 of 11 checks passed
@Gnanasundari24 Gnanasundari24 deleted the payment-link-api-contract-change branch January 8, 2024 12:25
pixincreate added a commit that referenced this pull request Jan 9, 2024
* 'main' of github.com:juspay/hyperswitch:
  feat(pm_list): add required fields for Ideal  (#3183)
  refactor: pass customer object to `make_pm_data` (#3246)
  feat(Connector): [VOLT] Add support for Payments Webhooks (#3155)
  fix(users): Added merchant name is list merchants (#3289)
  fix(outgoingwebhookevents): Throw an error when outgoing webhook events env var not found (#3291)
  fix(wasm): fix failing `wasm-pack build` for `euclid_wasm` (#3284)
  ci: add workflow to create stable SemVer tag for a given CalVer tag (#3285)
  fix(connector): [BOA, Cybersource] capture error_code (#3239)
  fix(connector): [BOA/CYB] Fix Metadata Error (#3283)
  chore(version): 2024.01.08.0
  fix: introduce net_amount field in payment response (#3115)
  ci(postman): Adyen assertion fix for expired card test case  (#3279)
  feat(connector): Add Revoke mandate flow (#3261)
  refactor(drainer): change logic for trimming the stream and refactor for modularity (#3128)
  fix(router): Payment link api contract change (#2975)
  feat(pm_list): add required fields for eps (#3169)
  refactor(api_lock): allow api lock on psync only when force sync is true (#3242)
  fix(router): multiple incremental_authorizations with kv enabled (#3185)
  feat(payments): add payment id in all the payment logs (#3142)
  ci: add reusable workflow to create nightly tags in CalVer format (#3247)
@SanchithHegde SanchithHegde removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows M-api-contract-changes Metadata: This PR involves API contract changes M-database-changes Metadata: This PR involves database schema changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.