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(payout): [Payone] add payone connector #4553

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

KiranKBR
Copy link
Contributor

@KiranKBR KiranKBR commented May 6, 2024

Type of Change

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

Description

Merchant Connector:

--header 'Content-Type: application/json' \
--header 'api-key: test_admin' \
--data '{
    "connector_type": "payout_processor",
    "connector_name": "payone",
    "connector_account_details": {
        "auth_type": "SignatureKey",
        "api_key": "",
        "api_secret": "",
        "key1": ""
    },
    "test_mode": false,
    "disabled": false,
    "business_country": "US",
    "business_label": "default",
    "payment_methods_enabled": [
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        
                
                        "Mastercard",
                        "Visa"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "AmericanExpress",
                        "Discover",
                        "Interac",
                        "JCB",
                        "Mastercard",
                        "Visa",
                        "DinersClub",
                        "UnionPay",
                        "RuPay"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "wallet",
            "payment_method_types": [
                {
                    "payment_method_type": "paypal",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": false,
                    "installment_payment_enabled": false
                }
            ]
        }
    ],
    "metadata": {
        "city": "NY",
        "unit": "245"
    }
}'

response:

{
    "connector_type": "payout_processor",
    "connector_name": "payone",
    "connector_label": "payone_US_default",
    "merchant_connector_id": "mca_Rufh4UB4ctrHhOV8JQzG",
    "profile_id": "pro_cp4l2sD7NggkM66Cvrfz",
    "connector_account_details": {
        "auth_type": "SignatureKey",
        "api_key": "",
        "api_secret": "",
        "key1": ""
    },
    "payment_methods_enabled": [
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "credit",
                    "payment_experience": null,
                    "card_networks": [
                        "Mastercard",
                        "Visa"
                    ],
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "debit",
                    "payment_experience": null,
                    "card_networks": [
                        "AmericanExpress",
                        "Discover",
                        "Interac",
                        "JCB",
                        "Mastercard",
                        "Visa",
                        "DinersClub",
                        "UnionPay",
                        "RuPay"
                    ],
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "wallet",
            "payment_method_types": [
                {
                    "payment_method_type": "paypal",
                    "payment_experience": "redirect_to_url",
                    "card_networks": null,
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": false,
                    "installment_payment_enabled": false
                }
            ]
        }
    ],
    "connector_webhook_details": null,
    "metadata": {
        "city": "NY",
        "unit": "245"
    },
    "test_mode": false,
    "disabled": false,
    "frm_configs": null,
    "business_country": "US",
    "business_label": "default",
    "business_sub_label": null,
    "applepay_verified_domains": null,
    "pm_auth_config": null,
    "status": "active"
}

Payout Creation:

{
    "amount": 100,
    "currency": "EUR",
    "customer_id": "payout_customer",
    "email": "payout_customer@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "Its my first payout request",
    "payout_type": "card",
    "payout_method_data": {
        "card": {
            "card_number": "4012000033330026",
            "expiry_month": "05",
            "expiry_year": "30",
            "card_holder_name": "John Smith"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "NY",
            "zip": "94122",
            "country": "US",
            "first_name": "John",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        }
    },
    "entity_type": "Individual",
    "recurring": false,
    "metadata": {
        "ref": "123"
    },
        "business_country": "US",
    "business_label": "default",
    // "routing": {
    //     "type": "single",
    //     "data": "adyen"
    // },
    "auto_fulfill": true,
    "confirm": true
}

response:

{
    "payout_id": "5ec9e6ac-1bbc-4236-a217-e0ff890e7f2e",
    "merchant_id": "merchant_1715339934",
    "amount": 100,
    "currency": "EUR",
    "connector": "payone",
    "payout_type": "card",
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "NY",
            "first_name": "John",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": null
    },
    "customer_id": "payout_customer",
    "auto_fulfill": true,
    "email": "payout_customer@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "client_secret": null,
    "return_url": null,
    "business_country": "US",
    "business_label": "default",
    "description": "Its my first payout request",
    "entity_type": "Individual",
    "recurring": false,
    "metadata": {
        "ref": "123"
    },
    "status": "success",
    "error_message": null,
    "error_code": null,
    "profile_id": "pro_cp4l2sD7NggkM66Cvrfz",
    "created": "2024-05-10T11:25:54.497Z"
}

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?

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

@KiranKBR KiranKBR requested review from a team as code owners May 6, 2024 06:16
@KiranKBR KiranKBR changed the title (feat) : [Payone Payout] added flows feat(payout): [Payone] May 6, 2024
@KiranKBR KiranKBR changed the title feat(payout): [Payone] feat(payout): [Payone] add payone connector May 6, 2024
@Sakilmostak
Copy link
Contributor

Required CI checks are failing, could you address that

@KiranKBR KiranKBR linked an issue May 7, 2024 that may be closed by this pull request
2 tasks
@KiranKBR KiranKBR added A-connector-integration Area: Connector integration C-feature Category: Feature request or enhancement labels May 7, 2024
@KiranKBR KiranKBR self-assigned this May 7, 2024
@KiranKBR KiranKBR added the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label May 8, 2024
@KiranKBR KiranKBR changed the base branch from main to payone-template-code May 8, 2024 09:22
@KiranKBR KiranKBR requested review from a team as code owners May 8, 2024 09:22
@Sakilmostak Sakilmostak removed request for a team May 15, 2024 07:33
date_header.trim(),
canonicalized_path.trim()
);
println!("{string_to_hash:?}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this print statement

Comment on lines +68 to +76
pub fn get_current_date_time() -> CustomResult<String, errors::ConnectorError> {
let format = format_description::parse(
"[weekday repr:short], [day] [month repr:short] [year] [hour]:[minute]:[second] GMT",
)
.change_context(errors::ConnectorError::InvalidDateFormat)?;
OffsetDateTime::now_utc()
.format(&format)
.change_context(errors::ConnectorError::InvalidDateFormat)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move this into utils

Copy link
Contributor

Choose a reason for hiding this comment

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

Please create the utils function in an generalized manner so that the format can be passed as an argument. @KiranKBR

req,
))?;
let connector_req = payone::PayoneRefundRequest::try_from(&connector_router_data)?;
let connector_req = payone::PayonePayoutFulfillRequest::try_from(req)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Create PayoneRouterData first, then create request body

Suggested change
let connector_req = payone::PayonePayoutFulfillRequest::try_from(req)?;
let connector_router_data = payone::PayoneRouterData::try_from((
&self.get_currency_unit(),
req.request.destination_currency,
req.request.amount,
req,
))?;
let connector_req = payone::PayonePayoutFulfillRequest::try_from(&connector_router_data)?;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not required

}

impl TryFrom<&types::ConnectorAuthType> for PayoneAuthType {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(auth_type: &types::ConnectorAuthType) -> Result<Self, Self::Error> {
match auth_type {
types::ConnectorAuthType::HeaderKey { api_key } => Ok(Self {
if let types::ConnectorAuthType::SignatureKey {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use match statement instead of if let to for the ConnectorAuthType and state all the enums to know explicitly what we are handling

Comment on lines 131 to 145
impl Card {
fn get_card_issuer(&self) -> Result<CardIssuer, Error> {
for (k, v) in CARD_REGEX.iter() {
let regex: Regex = v
.clone()
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
if regex.is_match(self.card_number.clone().get_card_no().as_str()) {
return Ok(*k);
}
}
Err(error_stack::Report::new(
errors::ConnectorError::NotImplemented("Card Type".into()),
))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this and use the one from utils

refund_status: enums::RefundStatus::from(item.response.status),
response: Ok(types::PayoutsResponseData {
status: Some(storage_enums::PayoutStatus::foreign_from(response.status)),
connector_payout_id: "".to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
connector_payout_id: "".to_string(),
connector_payout_id: response.id,

You can provide the id present in response as connector_payout_id

@@ -1096,6 +1096,7 @@ pub trait CardData {
fn get_expiry_date_as_mmyyyy(&self, delimiter: &str) -> Secret<String>;
fn get_expiry_year_4_digit(&self) -> Secret<String>;
fn get_expiry_date_as_yymm(&self) -> Result<Secret<String>, errors::ConnectorError>;
fn get_expiry_date_as_mmyy(&self) -> Result<Secret<String>, errors::ConnectorError>;
Copy link
Contributor

Choose a reason for hiding this comment

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

No need of this util, you can use this function get_card_expiry_month_year_2_digit_with_delimiter

Comment on lines +1796 to +1799
api_enums::Connector::Payone => {
payone::transformers::PayoneAuthType::try_from(val)?;
Ok(())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please place this in alphabetical order

Comment on lines 14 to 15
connector: Box::new(&Payone),
connector_name: types::Connector::Adyen,
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose you need to change the name to Payone

Suggested change
connector: Box::new(&Payone),
connector_name: types::Connector::Adyen,
connector: Box::new(&Payone),
connector_name: types::Connector::Payone,

@@ -282,6 +285,7 @@ impl ConnectorConfig {
Connector::Noon => Ok(connector_data.noon),
Connector::Nuvei => Ok(connector_data.nuvei),
Connector::Payme => Ok(connector_data.payme),
Connector::Payone => Err("Use get_payout_connector_config".to_string()),
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the difference between Ebanx and Payone? why are we throwing error here?

Comment on lines +68 to +76
pub fn get_current_date_time() -> CustomResult<String, errors::ConnectorError> {
let format = format_description::parse(
"[weekday repr:short], [day] [month repr:short] [year] [hour]:[minute]:[second] GMT",
)
.change_context(errors::ConnectorError::InvalidDateFormat)?;
OffsetDateTime::now_utc()
.format(&format)
.change_context(errors::ConnectorError::InvalidDateFormat)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please create the utils function in an generalized manner so that the format can be passed as an argument. @KiranKBR

currency_code: item.router_data.request.destination_currency.to_string(),
};
let _card_issuer =
CardAndCardIssuer::try_from(&item.router_data.get_payout_method_data()?)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

This try_from is not required rather add a match on payment_method_data and then impl a try_from to return the whole Object card_payout_method_specific_input


let card_payout_method_specific_input: CardPayoutMethodSpecificInput =
CardPayoutMethodSpecificInput {
#[allow(clippy::as_conversions)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this lint added?

Comment on lines +181 to 190
match issuer {
CardIssuer::Master => Ok(Self::MasterCard),
CardIssuer::Visa => Ok(Self::Visa),
_ => Err(errors::ConnectorError::NotImplemented(
get_unimplemented_payment_method_error_message("payone"),
)
.into()),
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we not covering all the card issuer networks?

}),
..item.data
})
#[allow(dead_code)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why dead_code?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also Serialize is not required in the derives as this is response.
Please take care of this at all the applicable places

Comment on lines +269 to +270
PayoneStatus::RejectedCredit | PayoneStatus::Rejected => Self::Cancelled,
PayoneStatus::Cancelled | PayoneStatus::Reversed => Self::Cancelled,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
PayoneStatus::RejectedCredit | PayoneStatus::Rejected => Self::Cancelled,
PayoneStatus::Cancelled | PayoneStatus::Reversed => Self::Cancelled,
PayoneStatus::RejectedCredit | PayoneStatus::Rejected |
PayoneStatus::Cancelled | PayoneStatus::Reversed => Self::Cancelled,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-connector-integration Area: Connector integration C-feature Category: Feature request or enhancement S-waiting-on-review Status: This PR has been implemented and needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants