Subversion Repositories SmartDukaan

Rev

Rev 18578 | Blame | Compare with Previous | Last modification | View Log | RSS feed

namespace java in.shop2020.payments
namespace py shop2020.thriftpy.payments

include "GenericService.thrift"

/**
Various structures
**/
enum PaymentGatewayStatus{
        AVAILABLE,
        BLOCKED
}

enum PaymentStatus{
        INIT,
        PENDING,
        SUCCESS,        // HDFC Status: CAPTURED; EBS Status: Captured
        FAILED,         // HDFC status: NOT CAPTURED, DENIED BY RISK, HOST TIMEOUT, CANCELLED
        AUTHORIZED,  // EBS Status: Pending, HDFC Status: APPROVED
        PARTIALLY_CAPTURED, //In case of COD
        CAPTURE_IN_PROCESS, // In case first few attempts to capture failed due to transient connections issues
        PROVISIONALLY_CAPTURED, // In case payment is not getting
        REFUNDED,
        PENDING_APPROVAL 
}

// If new paymethod is added here, sales database for pentaho must also be updated.
const map<string,string> PAYMENT_METHOD = {
        '1001' : 'EBS-TEST Payment'
        '1004' : 'EBS-AXIS Bank Account'
        '1007' : 'EBS-HDFC Bank Account'
        '1008' : 'EBS-VISA'
        '1009' : 'EBS-Citi Bank Debit Card'
        '1010' : 'EBS-Diners Club'
        '1012' : 'EBS-ItzCash'
        '1015' : 'JK Bank Account'
        '1016' : 'ICICI Bank Account'
        '1017' : 'EBS-MasterCard'
        '1029' : 'Federal Bank Account'
        '1032' : 'State Bank of India Netbanking'
        '1033' : 'State Bank of Bikaner and Jaipur Netbanking'
        '1034' : 'State Bank of Hyderabad Netbanking'
        '1035' : 'State Bank of Patiala Netbanking'
        '1036' : 'State Bank of Shaurashtra Netbanking'
        '1037' : 'State Bank of Indore Netbanking'
        '1038' : 'State Bank of Mysore Netbanking'
        '1039' : 'State Bank of Travancore Netbanking'
        '1040' : 'EBS-Citi Bank Reward Point',
        '1154' : 'ORIENTAL BANK OF COMMERCE Netbanking',
        '1210' : 'ING VYSYA BANK Netbanking',
        '1224' : 'CANARA BANK Netbanking'
        '1127' : 'Citi Bank NetBanking'
        '1132' : 'EBS-Done Card'
        '1133' : 'Karnataka Bank Account'
        '1134' : 'EBS-ICash'
        '1135' : 'Corporation Bank Account'
        '1212' : 'United Bank of India'
        '1213' : 'Indian Overseas Bank'
        '1214' : 'Bank of India'
        '1215' : 'City Union Bank'
        '1216' : 'Union Bank of India'
        '1273' : 'Dhanalaxmi Bank'
        '1601' : 'Catholic Syrian Bank'
        '1602' : 'Development Credit Bank'
        '1603' : 'Deutsche Bank'
        '1604' : 'IDBI Bank'
        '1605' : 'IndusInd Bank'
        '1606' : 'Karur Vysya - Retail Netbanking'
        '1607' : 'Punjab National Bank - Retail Banking'
        '1608' : 'South Indian Bank'
        '1609' : 'Saraswat Bank'
        '1610' : 'Vijaya Bank'
        '1611' : 'DCB Bank - Corporate Netbanking'
        '1612' : 'Union Bank - Corporate Netbanking'
        '1613' : 'Punjab National Bank-Corporate'
        
        '2000' : 'HDFC-VISA/VISA Electron Debit Card'
        '2008' : 'HDFC-VISA'
        '2017' : 'HDFC-MasterCard Credit Card'
        '2018' : 'HDFC-MasterCard Debit Card'
        '3000' : 'COD'
        '3001' : 'Coupon'
        '2001' : 'Cheque'
        '1026' : 'EBS-ICICI Bank Debit Card'
    '1027' : 'EBS-SBI Debit Card'
    '2020' : 'HDFC Credit Card 3-month EMI'
    '5001' : 'HDFC Credit Card 3-month EMI'
    '5002' : 'HDFC Credit Card 6-month EMI'
    '5003' : 'HDFC Credit Card 9-month EMI'
    '5004' : 'HDFC Credit Card 12-month EMI'
    '5005' : 'HDFC Credit Card 18-month EMI'
    '1139' : 'Citi EBS-VISA Credit Card 3-months EMI'
    '1140' : 'Citi EBS-MasterCard Credit Card 3-months EMI'
    '1141' : 'Citi EBS-VISA Credit Card 6-months EMI'
    '1142' : 'Citi EBS-MasterCard Credit Card 6-months EMI'
    '1143' : 'EBS-Indian Bank Netbanking'
    '1164' : 'EBS-Maestro Debit Card'
    '4000' : 'BULK',
    '4001' : 'PAYU MONEY',
    '210000':'Axis Bank Innoviti 3 Months EMI',
    '220000':'Axis Bank Innoviti 6 Months EMI',
    '230000':'Axis Bank Innoviti 9 Months EMI',
    '240000':'Axis Bank Innoviti 12 Months EMI',
    '250000':'Axis Bank Innoviti 18 Months EMI',
    '310000':'ICICI Bank Innoviti 3 Months EMI',
    '320000':'ICICI Bank Innoviti 6 Months EMI',
    '330000':'ICICI Bank Innoviti 9 Months EMI',
    '340000':'ICICI Bank Innoviti 12 Months EMI',
    '350000':'ICICI Bank Innoviti 18 Months EMI',
    '410000':'InsdusInd Bank Innoviti 3 Months EMI',
    '420000':'InsdusInd Bank Innoviti 6 Months EMI',
    '430000':'InsdusInd Bank Innoviti 9 Months EMI',
    '440000':'InsdusInd Bank Innoviti 12 Months EMI',
    '510000':'Citi Bank Innoviti 3 Months EMI',
    '520000':'Citi Bank Innoviti 6 Months EMI',
    '530000':'Citi Bank Innoviti 9 Months EMI',
    '540000':'Citi Bank Innoviti 12 Months EMI',
    '456789':'Capital Float',
    '610000':'Standard Chartered Bank Innoviti 3 Months EMI',
    '620000':'Standard Chartered Bank Innoviti 6 Months EMI',
    '630000':'Standard Chartered Bank Innoviti 9 Months EMI',
    '640000':'Standard Chartered Bank Innoviti 12 Months EMI',
    '710000':'HSBC Bank Innoviti 3 Months EMI',
    '720000':'HSBC Bank Innoviti 6 Months EMI',
    '730000':'HSBC Bank Innoviti 6 Months EMI',
    '740000':'HSBC Bank Innoviti 6 Months EMI',
    '810000':'Kotak Mahindra Bank Innoviti 3 Months EMI',
    '820000':'Kotak Mahindra Bank Innoviti 6 Months EMI',
    '830000':'Kotak Mahindra Bank Innoviti 9 Months EMI',
    '840000':'Kotak Mahindra Bank Innoviti 12 Months EMI',
    '910000':'SBI Bank Innoviti 3 Months EMI',
    '920000':'SBI Bank Innoviti 6 Months EMI',
    '930000':'SBI Bank Innoviti 9 Months EMI',
    '940000':'SBI Bank Innoviti 12 Months EMI',
    '950000':'SBI Bank Innoviti 18 Months EMI'
}

struct Attribute{
        1:string name,
        2:string value
}

struct PaymentGateway{
        1:i64 id,
        2:string name,
        3:string url,
        4:i64 addedOn,
        5:string aliasName,
        6:string responseUrl,
        7:string errorUrl,
        8:PaymentGatewayStatus status
        9:list<Attribute> attributes  // list of all attributes for PG
}

struct Payment{
        1:i64 paymentId,                                // trackId for bank, paymentid for us and id for table.
        2:i64 gatewayId,                                //payment gateway used
        3:string gatewayPaymentId
        4:i64 merchantTxnId,                    //merchant transaction id. This will be propagated further to order processing
        5:string gatewayTxnId,                  //bank trnasaction id
        6:double amount,
        7:string gatewayTxnStatus,      // bank status will be stored here
        8:PaymentStatus status,
        9:i64 userId,                                   //The user for which payment has to be processed.This is here to speed up querying.
        10:string errorCode,
        11:string description,
        12:string authCode,
        13:string referenceCode,                // given by gateway
        14:string sessionId,                    // received from PG 
        15:string gatewayTxnDate,
        16:list<Attribute> attributes,          // list of all attributes received from PG
        17:i64 initTimestamp,                   //statring the payment processing timestamp
        18:i64 successTimestamp,                //timestamp when payment is captured
        19:i64 errorTimestamp,                  // in case, error is received from PG
        20:i64 provisionalCaptureTimestamp, // in case, error is received from PG
        21:bool isDigital,
        22:double refundAmount
}

struct Refund{
        1:i64 id,
        2:i64 paymentId,
    3:i64 gatewayId,
    4:i64 orderId,
    5:double amount,
    6:string gatewayTxnId,
    7:i32 attempts,
    8:i64 createdAt,
    9:i64 processedAt,
    10:list<Attribute> attributes
}

exception PaymentException{
        1:i64 error_code,
        2:string message
}

enum ExtraPaymentProcessingType {
    FAILED_PAYMENTS,
    PENDING_CAPTURE
}

service PaymentService extends GenericService.GenericService{
        /**
        create a new payment and return payment id, throws an exception if gateway is not active
        */
        i64 createPayment(1:i64 userId, 2:double amount, 3:i64 gatewayId, 4:i64 txnId, 5:bool isDigital) throws (1:PaymentException pe),
        
        /**
        Get all payments for user. If status and gateway are null, they are ignored. Same for times as well.
        */ 
        list<Payment> getPaymentsForUser(1:i64 userId, 2:i64 fromTime, 3:i64 toTime, 4:PaymentStatus status, 5:i64 gatewayId) throws (1:PaymentException pe),
        
        /**
        Get all payments in the given status for the given gateway. If gatewayId is 0, then it is ignored.
        */ 
        list<Payment> getPayments(1:i64 fromTime, 2:i64 toTime, 3:PaymentStatus status, 4:i64 gatewayId) throws (1:PaymentException pe),
        
        /**
        Get all payments for the given gateway which were captured between the given dates. If the gatewayId is 0, it's ignored.
        */
        list<Payment> getPaymentsByCapturedDate(1:i64 fromTime, 2:i64 toTime, 3:i64 gatewayId) throws (1:PaymentException pe),  
        
        /** 
        Get the gateway for the given id. 
        */
        PaymentGateway getPaymentGateway(1:i64 id) throws (1:PaymentException pe),
        
        /**
         *Get all active Payment Gateways
         **/
        list<PaymentGateway> getActivePaymentGateways() throws (1:PaymentException pe),
        
        /** 
        * Get a particular payment info
        **/
        Payment getPayment(1:i64 id) throws (1:PaymentException pe),


        /** 
        * Get payments for a transaction. Will raise exception.
        **/
        list<Payment> getPaymentForTxnId(1:i64 txnId) throws (1:PaymentException pe),
        
        /** 
        * Get payments for a recharge transaction id. Will raise exception.
        **/
        list<Payment> getPaymentForRechargeTxnId(1:i64 txnId) throws (1:PaymentException pe),
        
        /** 
        * Get successful payment for a transaction. Will raise exception.
        **/
        Payment getSuccessfulPaymentForTxnId(1:i64 txnId) throws (1:PaymentException pe),
        
        /**
        * mark payment successful and store parameters
        **/
        bool updatePaymentDetails(1:i64 id, 2:string gatewayPaymentId, 3:string sessionId, 4:string gatewayTxnStatus, 5:string  description, 6:string gatewayTxnId, 7:string authCode, 8:string referenceCode, 9:string errorCode, 10:PaymentStatus  status, 11:string gatewayTxnDate, 12:list<Attribute> attributes) throws (1:PaymentException pe),
        
        /**
        * mark payment failed and store parameters
        
        bool markPaymentFailed(1:i64 id, 2:string gatewayPaymentId, 3:string sessionId, 4:string gatewayTxnStatus, 5:string description, 6:string errorCode, 7:list<Attribute> attributes )  throws (1:PaymentException pe)
        */
                
        /**
        Returns the minimum and maximum amounts among successful payments.
        List contains two double values, first minimum and second maximum amount.
        */
        list<double> getSuccessfulPaymentsAmountRange(),
        
        /**
        Initialize the payment pipe for a HDFC payment. The URL the user should be redirected to is returned.
        In case of any processing error, an exception is raised.
        */
        string initializeHdfcPayment(1:i64 merchantPaymentId, 2:bool isMobile) throws (1:PaymentException pe),
        
        /**
        Initialize the payment pipe for a HDFC payment in case of a digital order. The URL the user should be redirected to is returned.
        In case of any processing error, an exception is raised. The phone is a madatory field and is required in case of dth payments.
        */
        string doHdfcPaymentForDigitalOrder(1:i64 merchantPaymentId, 2:i64 rechargeOrderId, 3:string phone, 4:bool isMobile) throws (1:PaymentException pe),
        
        /**
        Initialize the payment pipe for a HDFC EMI payment. The URL the user should be redirected to is returned.
        In case of any processing error, an exception is raised.
        */
        string initializeHdfcEmiPayment(1:i64 merchantPaymentId, 2:bool isMobile) throws (1:PaymentException pe),
        
        /**
        Create a refund of the given amount corresponding to the given order to be processed through the same
        payment gateway which processed the payment for the corresponding transaction.
        Returns the id of the newly created Refund.
        */      
        i64 createRefund(1:i64 orderId, 2:i64 merchantTxnId, 3:double amount) throws (1:PaymentException pe),
        
        /**
        Capture the payment for the given merchant transaction id. It processes the last payment for the given
        transaction. If the capture attempt failed, the payment is marked as failed. PaymentException with error 
        code 104 is     thrown in case no payments are found for the transaction id passed. PaymentException is also
        thrown with error code 106 in case capture was not possible due to connection
        issue. 
        */
        bool capturePayment(1:i64 merchantTxnId, 2:bool isDigital) throws (1:PaymentException pe),
        
        /**
        Refund the payment for the given merchant transaction id. It processes the last payment for the given
        transaction. If refund will be failed nothing will be updated in database.
        */
        bool refundPayment(1:i64 merchantTxnId, 2:double amount, 3:bool isDigital) throws (1:PaymentException pe),
        
        
        /**
        Adds the given amount to the captured amount of a COD payment.
        Updates the captured amount for the corresponding payment and marks it as PARTIALLY CAPTURED.
        If the captured amount becomes equal to total amount, then the payment status is set as SUCCESS.
        Also sets the name of the entity which transferred the money, the date on which it was transferred
        and the corresponding transaction id.
        
        Returns false if the payment couldn't be captured.
        Throws exception if no such payment could be found or if the captured amount will exceed the total amount after capturing.
        */
        bool partiallyCapturePayment(1:i64 merchantTxnId, 2:double amount, 3:string xferBy, 4:string xferTxnId, 5:i64 xferDate) throws (1:PaymentException pe),

    /**
     * Returns the list of payments that require some extra processing and
     * which belong to a particular category. This is currently used by CRM
     * application.
     */
    list<i64> getPaymentsRequiringExtraProcessing(1:ExtraPaymentProcessingType category),

    /**
     * Marks a particular payment as processed for a particular cateogory.
     * It essentially deletes the payment if it is processed for a particular
     * category. This is currently used by CRM application.
     */
    void markPaymentAsProcessed(1:i64 paymentId, 2:ExtraPaymentProcessingType category),
    
    PaymentStatus getPaymentStatusAtGateway(1:i64 merchantTxnId, 2:double amount, 3:bool isDigital) throws (1:PaymentException pe)
        
}