#[cfg(not(feature = "std"))]
use alloc::{borrow::ToOwned, format, string::String, vec::Vec};
use chrono::{serde::ts_seconds_option, DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::{
api::RequestParams,
common::{Country, Object},
error::{InternalApiResult, RazorpayResult},
ids::AccountId,
util::deserialize_notes,
Razorpay,
};
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum AccountType {
Standard,
}
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum AccountStatus {
Created,
Activated,
NeedsClarification,
UnderReview,
Suspended,
Rejected,
}
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum BusinessType {
#[default]
Proprietorship,
Partnership,
PrivateLimited,
PublicLimited,
Llp,
Ngo,
Trust,
Society,
NotYetRegistered,
Huf,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum BusinessCategory {
FinancialServices,
Education,
Healthcare,
Utilities,
Government,
Logistics,
ToursAndTravel,
Transport,
Ecommerce,
Food,
#[serde(rename = "it_and_software")]
ITAndSoftware,
Gaming,
MediaAndEntertainment,
Services,
Housing,
NotForProfit,
Social,
Others,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum BusinessSubCategory {
MutualFund,
Lending,
Cryptocurrency,
Insurance,
#[serde(rename = "nbfc")]
NBFC,
Cooperatives,
PensionFund,
Forex,
Securities,
Commodities,
Accounting,
FinancialAdvisor,
Crowdfunding,
Trading,
Betting,
GetRichSchemes,
MoneysendFunding,
WireTransferAndMoneyOrders,
TaxPreparationServices,
TaxPayments,
DigitalGoods,
#[serde(rename = "atms")]
ATMs,
College,
School,
University,
ProfessionalCourses,
DistanceLearning,
DayCare,
Coaching,
Elearning,
VocationalAndTradeSchools,
SportingClubs,
DanceHallsStudiosAndSchools,
CorrespondenceSchools,
Pharmacy,
Clinic,
Hospital,
Lab,
Dietician,
Fitness,
HealthCoaching,
HealthProducts,
DrugStores,
HealthcareMarketplace,
Osteopaths,
MedicalEquipmentAndSupplyStores,
PodiatristsAndChiropodists,
DentistsAndOrthodontists,
HardwareStores,
Ophthalmologists,
OrthopedicGoodsStores,
TestingLaboratories,
Doctors,
HealthPractitionersMedicalServices,
EcommerceMarketplace,
Agriculture,
Books,
ElectronicsAndFurniture,
Coupons,
Rental,
FashionAndLifestyle,
Gifting,
Grocery,
BabyProducts,
OfficeSupplies,
Wholesale,
ReligiousProducts,
PetProducts,
SportsProducts,
ArtsAndCollectibles,
SexualWellnessProducts,
DropShipping,
CryptoMachinery,
Tobacco,
WeaponsAndAmmunitions,
StampsAndCoinsStores,
OfficeEquipment,
AutomobilePartsAndEquipements,
GardenSupplyStores,
HouseholdApplianceStores,
NonDurableGoods,
PawnShops,
ElectricalPartsAndEquipment,
WigAndToupeeShops,
GiftNoveltyAndSouvenirShops,
DutyFreeStores,
OfficeAndCommercialFurniture,
DryGoods,
BooksAndPublications,
CameraAndPhotographicStores,
RecordShops,
MeatSupplyStores,
LeatherGoodsAndLuggage,
SnowmobileDealers,
MenAndBoysClothingStores,
PaintSupplyStores,
AutomotiveParts,
JewelleryAndWatchStores,
AutoStoreHomeSupplyStores,
TentStores,
ShoeStoresRetail,
PetroleumAndPetroleumProducts,
DepartmentStores,
AutomotiveTireStores,
SportApparelStores,
VarietyStores,
ChemicalsAndAlliedProducts,
CommercialEquipments,
FireplacePartsAndAccessories,
FamilyClothingStores,
FabricAndSewingStores,
HomeSupplyWarehouse,
ArtSupplyStores,
CamperRecreationalAndUtilityTrailerDealers,
ClocksAndSilverwareStores,
DiscountStores,
SchoolSuppliesAndStationery,
SecondHandStores,
WatchAndJewelleryRepairStores,
LiquorStores,
BoatDealers,
OpticiansOpticalGoodsAndEyeglasseStores,
WholesaleFootwearStores,
CosmeticStores,
HomeFurnishingStores,
AntiqueStores,
PlumbingAndHeatingEquipment,
TelecommunicationEquipmentStores,
WomenClothing,
Florists,
ComputerSoftwareStores,
BuildingMaterialStores,
CandyNutConfectioneryStores,
GlassAndWallpaperStores,
CommercialPhotographyAndGraphicDesignServices,
VideoGameSupplyStores,
FuelDealers,
DraperyAndWindowCoveringsStores,
HearingAidsStores,
AutomotivePaintShops,
DurableGoodsStores,
UniformsAndCommercialClothingStores,
FurShops,
IndustrialSupplies,
BicycleStores,
MotorcycleShopsAndDealers,
ChildrenAndInfantsWearStores,
WomenAccessoryStores,
ConstructionMaterials,
BooksPeriodicalsAndNewspaper,
FloorCoveringStores,
CrystalAndGlasswareStores,
AccessoryAndApparelStores,
HardwareEquipmentAndSupplyStores,
ComputerPeripheralEquipmentSoftware,
AutomobileAndTruckDealers,
AircraftAndFarmEquipmentDealers,
AntiqueShopsSalesAndRepairs,
MusicStores,
FurnitureAndHomeFurnishingStore,
RepairAndCleaning,
InteriorDesignAndArchitect,
MoversAndPackers,
Legal,
EventPlanning,
ServiceCentre,
Consulting,
AdAndMarketing,
ServicesClassifieds,
MultiLevelMarketing,
ConstructionServices,
ArchitecturalServices,
CarWashes,
MotorHomeRentals,
StenographicAndSecretarialSupportServices,
Chiropractors,
AutomotiveServiceShops,
ShoeRepairShops,
TelecommunicationService,
Fines,
SecurityAgencies,
Tailors,
TypeSettingAndEngravingServices,
SmallApplianceRepairShops,
PhotographyLabs,
DryCleaners,
MassageParlors,
ElectronicRepairShops,
CleaningAndSanitationServices,
NursingCareFacilities,
DirectMarketing,
Lottery,
VeterinaryServices,
AffliatedAutoRental,
AlimonyAndChildSupport,
AirportFlyingFields,
GolfCourses,
TireRetreadingAndRepairShops,
TelevisionCableServices,
RecreationAndSportingCamps,
BarberAndBeautyShops,
AgriculturalCooperatives,
CarpentryContractors,
WreckingAndSalvagingServices,
AutomobileTowingservices,
VideoTapeRentalStores,
MiscellaneousRepairShops,
MotorHomesAndParts,
HorseOrDogRacing,
LaundryServices,
ElectricalContractors,
DebtMarriagePersonalCounselingService,
AirConditioningAndRefrigerationRepairShops,
CreditReportingAgencies,
HeatingAndPlumbingContractors,
CarpetAndUpholsteryCleaningServices,
SwimmingPools,
RoofingAndMetalWorkContractors,
InternetServiceProviders,
RecreationalCamps,
MasonryContractors,
ExterminatingAndDisinfectingServices,
AmbulanceServices,
FuneralServicesAndCrematories,
MetalServiceCentres,
CopyingAndBlueprintingServices,
FuelDispensers,
WeldingRepair,
MobileHomeDealers,
ConcreteWorkContractors,
BoatRentals,
PersonalShoppersAndShoppingClubs,
DoorToDoorSales,
TravelRelatedDirectMarketing,
LotteryAndBetting,
BandsOrchestrasAndMiscellaneousEntertainers,
FurnitureRepairAndRefinishing,
Contractors,
DirectMarketingAndSubscriptionMerchants,
TypewriterStoresSalesServiceAndRentals,
RecreationServices,
DirectMarketingInsuranceServices,
BusinessServices,
InboundTelemarketingMerchants,
PublicWarehousing,
OutboundTelemarketingMerchants,
ClothingRentalStores,
TransportationServices,
ElectricRazorStores,
ServiceStations,
PhotographicStudio,
ProfessionalServices,
Developer,
FacilityManagement,
#[serde(rename = "rwa")]
RWA,
Coworking,
RealestateClassifieds,
SpaceRental,
Charity,
Educational,
Religious,
Personal,
MatchMaking,
SocialNetwork,
Messaging,
ProfessionalNetwork,
NeighbourhoodNetwork,
PoliticalOrganizations,
AutomobileAssociationsAndClubs,
CountryAndAthleticClubs,
AssociationsAndMembership,
VideoOnDemand,
MusicStreaming,
Multiplex,
ContentAndPublishing,
Ticketing,
News,
VideoGameArcades,
VideoTapeProductionAndDistribution,
BowlingAlleys,
BilliardAndPoolEstablishments,
AmusementParksAndCircuses,
TicketAgencies,
GameDeveloper,
Esports,
OnlineCasino,
FantasySports,
GamingMarketplace,
Saas,
Paas,
Iaas,
ConsultingAndOutsourcing,
WebDevelopment,
TechnicalSupport,
DataProcessing,
OnlineFoodOrdering,
Restaurant,
FoodCourt,
Catering,
Alcohol,
RestaurantSearchAndBooking,
DairyProducts,
Bakeries,
Electricity,
Gas,
Telecom,
Water,
Cable,
Broadband,
#[serde(rename = "dth")]
DTH,
InternetProvider,
BillAndRechargeAggregators,
Central,
State,
IntraGovernmentPurchases,
GovernmentPostalServices,
Freight,
Courier,
Warehousing,
Distribution,
EndToEndLogistics,
CourierServices,
Aviation,
Accommodation,
#[serde(rename = "ota")]
OTA,
TravelAgency,
TouristAttractionsAndExhibits,
Timeshares,
AquariumsDolphinariumsAndSeaquariums,
CabHailing,
Bus,
TrainAndMetro,
AutomobileRentals,
CruiseLines,
ParkingLotsAndGarages,
Transportation,
BridgeAndRoadTolls,
FreightTransport,
TruckAndUtilityTrailerRentals,
}
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
pub struct Address {
pub street1: String,
pub street2: String,
pub city: String,
pub state: String,
pub postal_code: u16,
pub country: Country,
}
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
pub struct BusinessAddresses {
pub operation: Option<Address>,
pub registered: Address,
}
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
pub struct LegalInfo {
pub pan: Option<String>,
pub gst: Option<String>,
pub cin: Option<String>,
}
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
pub struct BrandInfo {
pub color: String,
}
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
pub struct BusinessProfile {
pub category: BusinessCategory,
pub subcategory: BusinessSubCategory,
#[deprecated(
since = "0.1.0",
note = "Please use `business_model` field instead"
)]
pub description: String,
pub business_model: String,
pub addresses: BusinessAddresses,
}
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
pub struct ContactDetails {
pub email: String,
pub phone: u64,
pub policy_url: String,
}
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
pub struct ContactInfo {
pub chargeback: ContactDetails,
pub refund: ContactDetails,
pub support: ContactDetails,
}
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
pub struct App {
pub name: String,
pub url: String,
}
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
pub struct Apps {
pub websites: Vec<String>,
pub android: Vec<App>,
pub ios: Vec<App>,
}
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
pub struct Account {
pub id: AccountId,
#[serde(rename = "type")]
pub type_: AccountType,
pub status: AccountStatus,
pub email: String,
pub phone: u64,
pub legal_business_name: String,
pub customer_facing_business_name: Option<String>,
pub business_type: BusinessType,
pub reference_id: Option<String>,
pub profile: Option<BusinessProfile>,
pub legal_info: Option<LegalInfo>,
pub brand: Option<BrandInfo>,
#[serde(deserialize_with = "deserialize_notes")]
pub notes: Object,
pub contact_name: String,
pub contact_info: Option<ContactInfo>,
pub apps: Option<Apps>,
#[serde(with = "ts_seconds_option")]
pub activated_at: Option<DateTime<Utc>>,
pub live: bool,
pub hold_funds: bool,
}
#[derive(Debug, Serialize, Clone, PartialEq, Eq)]
pub struct CreateOrUpdateAccountApp<'a> {
pub name: &'a str,
pub url: &'a str,
}
#[derive(Debug, Serialize, Clone, PartialEq, Eq)]
pub struct CreateOrUpdateAccountApps<'a> {
pub websites: &'a [&'a str],
pub android: &'a [CreateOrUpdateAccountApp<'a>],
pub ios: &'a [CreateOrUpdateAccountApp<'a>],
}
#[derive(Debug, Serialize, Clone, PartialEq, Eq)]
pub struct CreateOrUpdateAccountContactDetails<'a> {
pub email: &'a str,
pub phone: u64,
pub policy_url: &'a str,
}
#[derive(Debug, Serialize, Clone, PartialEq, Eq)]
pub struct CreateOrUpdateAccountContactInfo<'a> {
pub chargeback: CreateOrUpdateAccountContactDetails<'a>,
pub refund: CreateOrUpdateAccountContactDetails<'a>,
pub support: CreateOrUpdateAccountContactDetails<'a>,
}
#[derive(Debug, Serialize, Clone, PartialEq, Eq)]
pub struct CreateOrUpdateAccountBrandInfo<'a> {
pub color: &'a str,
}
#[derive(Debug, Default, Serialize, Clone, PartialEq, Eq)]
pub struct CreateOrUpdateAccountLegalInfo<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub pan: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub gst: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cin: Option<&'a str>,
}
#[derive(Debug, Serialize, Clone, PartialEq, Eq)]
pub struct CreateOrUpdateAccountAddress<'a> {
pub street1: &'a str,
pub street2: &'a str,
pub city: &'a str,
pub state: &'a str,
pub postal_code: u16,
pub country: Country,
}
#[derive(Debug, Serialize, Clone, PartialEq, Eq)]
pub struct CreateOrUpdateAccountAddresses<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub operation: Option<CreateOrUpdateAccountAddress<'a>>,
pub registered: CreateOrUpdateAccountAddress<'a>,
}
#[derive(Debug, Serialize, Clone, PartialEq, Eq)]
pub struct CreateOrUpdateAccountProfile<'a> {
pub category: BusinessCategory,
pub subcategory: BusinessSubCategory,
pub business_model: &'a str,
pub addresses: CreateOrUpdateAccountAddresses<'a>,
}
#[derive(Debug, Default, Serialize, Clone, PartialEq, Eq)]
pub struct CreateAccount<'a> {
pub email: &'a str,
pub phone: u64,
pub legal_business_name: &'a str,
#[serde(skip_serializing_if = "Option::is_none")]
pub customer_facing_business_name: Option<&'a str>,
pub business_type: BusinessType,
#[serde(skip_serializing_if = "Option::is_none")]
pub reference_id: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub profile: Option<CreateOrUpdateAccountProfile<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub legal_info: Option<CreateOrUpdateAccountLegalInfo<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub brand: Option<CreateOrUpdateAccountBrandInfo<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub notes: Option<Object>,
pub contact_name: &'a str,
#[serde(skip_serializing_if = "Option::is_none")]
pub contact_info: Option<CreateOrUpdateAccountContactInfo<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub apps: Option<CreateOrUpdateAccountApps<'a>>,
}
#[derive(Debug, Default, Serialize, Clone, PartialEq, Eq)]
pub struct UpdateAccount<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub phone: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub legal_business_name: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub customer_facing_business_name: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub business_type: Option<BusinessType>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reference_id: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub profile: Option<CreateOrUpdateAccountProfile<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub legal_info: Option<CreateOrUpdateAccountLegalInfo<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub brand: Option<CreateOrUpdateAccountBrandInfo<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub notes: Option<Object>,
#[serde(skip_serializing_if = "Option::is_none")]
pub contact_name: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub contact_info: Option<CreateOrUpdateAccountContactInfo<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub apps: Option<CreateOrUpdateAccountApps<'a>>,
}
impl Account {
pub async fn create(
razorpay: &Razorpay,
params: CreateAccount<'_>,
) -> RazorpayResult<Account> {
let res = razorpay
.api
.post(RequestParams {
url: "/accounts".to_owned(),
version: Some("v2".to_owned()),
data: Some(params),
})
.await?;
match res {
InternalApiResult::Ok(account) => Ok(account),
InternalApiResult::Err { error } => Err(error.into()),
}
}
pub async fn fetch(
razorpay: &Razorpay,
account_id: &AccountId,
) -> RazorpayResult<Account> {
let res = razorpay
.api
.get(RequestParams {
url: format!("/accounts/{}", account_id),
version: Some("v2".to_owned()),
data: None::<()>,
})
.await?;
match res {
InternalApiResult::Ok(account) => Ok(account),
InternalApiResult::Err { error } => Err(error.into()),
}
}
pub async fn update(
razorpay: &Razorpay,
account_id: &AccountId,
params: UpdateAccount<'_>,
) -> RazorpayResult<Account> {
let res = razorpay
.api
.post(RequestParams {
url: format!("/accounts/{}", account_id),
version: Some("v2".to_owned()),
data: Some(params),
})
.await?;
match res {
InternalApiResult::Ok(account) => Ok(account),
InternalApiResult::Err { error } => Err(error.into()),
}
}
pub async fn delete(
razorpay: &Razorpay,
account_id: &AccountId,
) -> RazorpayResult<()> {
let res: InternalApiResult<Value> = razorpay
.api
.delete(RequestParams {
url: format!("/accounts/{}", account_id),
version: Some("v2".to_owned()),
data: None::<()>,
})
.await?;
match res {
InternalApiResult::Ok(_) => Ok(()),
InternalApiResult::Err { error } => Err(error.into()),
}
}
}