def validate(self):
        """
    * Validate all set purchase details\n
    * @return boolean
    * @raises IPC_Exception
        """
        try:
            self._getCnf().validate()
        except Exception as ex:
            raise IPC_Exception(f'Invalid Config details: {ex}')

        if not Helper.versionCheck(self._getCnf().getVersion(), '1.4'):
            raise IPC_Exception(
                'IPCVersion ' + self._getCnf().getVersion() +
                ' does not support IPCAuthorizationCapture method. Please use 1.4 or above.'
            )

        if self.getCurrency() == None:
            raise IPC_Exception('Invalid currency')

        if self.getAmount() == None or not Helper.isValidAmount(
                self.getAmount()):
            raise IPC_Exception('Empty or invalid amount')

        return True
    def validate(self):
        """
    * Validate all set refund details\n
    * @return boolean
    * @raises IPC_Exception
        """
        try:
            self._getCnf().validate()
        except Exception as ex:
            raise IPC_Exception(f'Invalid Config details: {ex}')

        if self.getAmount() == None or not Helper.isValidAmount(
                self.getAmount()):
            raise IPC_Exception('Invalid Amount')

        if self.getCurrency() == None:
            raise IPC_Exception('Invalid Currency')

        if self.getTrnref() == None or not Helper.isValidTrnRef(
                self.getTrnref()):
            raise IPC_Exception('Invalid TrnRef')

        if self.getOrderID() == None or not Helper.isValidOrderId(
                self.getOrderID()):
            raise IPC_Exception('Invalid OrderId')

        if self.getOutputFormat() == None or not Helper.isValidOutputFormat(
                self.getOutputFormat()):
            raise IPC_Exception('Invalid Output format')

        return True
示例#3
0
    def add(self, itemName, quantity, price, type=ITEM_TYPE_ARTICLE):
        """
    * @param string itemName Item name
    * @param int quantity Items quantity
    * @param float price Single item price
    * @param string type\n
    * @return Cart
    * @raises IPC_Exception
        """
        if not bool(itemName):
            raise IPC_Exception('Invalid cart item name')

        if not bool(quantity) or not Helper.isValidCartQuantity(quantity):
            raise IPC_Exception('Invalid cart item quantity')

        if not bool(price) or not Helper.isValidAmount(price):
            raise IPC_Exception('Invalid cart item price')

        item = {
            'name': itemName,
            'quantity': quantity,
            'price': price,
        }

        if type == self.ITEM_TYPE_DELIVERY:
            item['delivery'] = 1
        elif type == self.ITEM_TYPE_DISCOUNT:
            item['price'] = num = -1 * abs(item['price'])

        self.__cart += item

        return self
 def getStatusMsg(self):
     """
 * Request param: StatusMsg\n
 * @return string
 * @raises IPC_Exception
     """
     return Helper.getArrayVal(self.getData(str.lower), 'statusmsg')
    def validate(self):
        """
    *  Validate all set config details\n
    *  @return boolean
    *  @raises IPC_Exception
        """
        if self.getKeyIndex() == None:
            raise IPC_Exception('Invalid Key Index')

        if self.getIpcURL() == None or not Helper.isValidURL(self.getIpcURL()):
            raise IPC_Exception('Invalid IPC URL')

        if self.getSid() == None:
            raise IPC_Exception('Invalid SID')

        if self.getWallet() == None or not self.getWallet().isnumeric():
            raise IPC_Exception('Invalid Wallet number')

        if self.getVersion() == None:
            raise IPC_Exception('Invalid IPC Version')

        try:
            Crypto.importKey(self.getPrivateKey())
        except:
            raise IPC_Exception(f'Invalid Private key')

        return True
 def getStatus(self):
     """
 * Request param: Status\n
 * @return int
 * @raises IPC_Exception
     """
     return Helper.getArrayVal(self.getData(str.lower), 'status')
 def _addPostParam(self, paramName: str, paramValue, encrypt = False):
     """
 *  Add API request param\n
 *  @param string paramName
 *  @param string paramValue
 *  @param bool encrypt
     """
     if not isinstance(paramValue, str):
         paramValue = str(paramValue)
     self.__params[paramName] = self.__encryptData(paramValue) if encrypt else Helper.escape(Helper.unescape(paramValue))
    def validate(self):
        """
    * Validate all set purchase details\n
    * @return boolean
    * @raises IPC_Exception
        """
        try:
            self._getCnf().validate()
        except Exception as ex:
            raise IPC_Exception(f'Invalid Config details: {ex}')

        if not Helper.versionCheck(self._getCnf().getVersion(), '1.4'):
            raise IPC_Exception(
                'IPCVersion ' + self._getCnf().getVersion() +
                ' does not support IPCIAPreAuthorization method. Please use 1.4 or above.'
            )

        if self.getItemName() == None or not isinstance(
                self.getItemName(), str):
            raise IPC_Exception('Empty or invalid item name.')

        if self.getCurrency() == None:
            raise IPC_Exception('Invalid currency')

        if self.getAmount() == None or not Helper.isValidAmount(
                self.getAmount()):
            raise IPC_Exception('Empty or invalid amount')

        if self.getCard() == None:
            raise IPC_Exception('Missing card details')

        if self.getCard().getCardToken() != None:
            raise IPC_Exception(
                'IPCIAPreAuthorization does not support card token.')

        try:
            self.getCard().validate()
        except Exception as ex:
            raise IPC_Exception(f'Invalid Card details: {ex}')

        return True
示例#9
0
    def validate(self):
        """
    * Validate all set purchase details\n
    * @return boolean
    * @raises IPC_Exception
        """
        if self.getUrlCancel() == None or not Helper.isValidURL(
                self.getUrlCancel()):
            raise IPC_Exception('Invalid Cancel URL')

        if self.getUrlNotify() == None or not Helper.isValidURL(
                self.getUrlNotify()):
            raise IPC_Exception('Invalid Notify URL')

        if self.getUrlOk() == None or not Helper.isValidURL(self.getUrlOk()):
            raise IPC_Exception('Invalid Success URL')

        if self.getCurrency() == None:
            raise IPC_Exception('Invalid currency')

        if self.getEmail() == None and self.getPhone() == None:
            raise IPC_Exception('Must provide customer email either phone')

        if self.getEmail() != None and not Helper.isValidEmail(
                self.getEmail()):
            raise IPC_Exception('Invalid Email')

        try:
            self._getCnf().validate()
        except Exception as ex:
            raise IPC_Exception(f'Invalid Config details: {ex}')

        if self.getCart() == None:
            raise IPC_Exception('Missing Cart details')

        try:
            self.getCart().validate()
        except Exception as ex:
            raise IPC_Exception(f'Invalid Cart details: {ex}')

        return True
示例#10
0
    def validate(self):
        """
    * Validate all set PreAuthorization details\n
    * @return boolean
    * @raises IPC_Exception
        """
        if not Helper.versionCheck(self._getCnf().getVersion(), '1.4'):
            raise IPC_Exception(
                'IPCVersion ' + self._getCnf().getVersion() +
                ' does not support IPCPreAuthorization method. Please use 1.4 or above.'
            )

        if self.getItemName() == None or not isinstance(
                self.getItemName(), str):
            raise IPC_Exception('Empty or invalid item name.')

        if self.getUrlCancel() == None or not Helper.isValidURL(
                self.getUrlCancel()):
            raise IPC_Exception('Invalid Cancel URL')

        if (self.getUrlNotify() == None
                or not Helper.isValidURL(self.getUrlNotify())):
            raise IPC_Exception('Invalid Notify URL')

        if self.getUrlOk() == None or not Helper.isValidURL(self.getUrlOk()):
            raise IPC_Exception('Invalid Success URL')

        if self.getAmount() == None or not Helper.isValidAmount(
                self.getAmount()):
            raise IPC_Exception('Empty or invalid amount')

        if self.getCurrency() == None:
            raise IPC_Exception('Invalid currency')

        try:
            self._getCnf().validate()
        except Exception as ex:
            raise IPC_Exception(f'Invalid Config details: {ex}')

        return True
示例#11
0
    def __createSignature(self):
        """
    *  Create signature of API Request params against the SID private key\n
    *  @return string base64 encoded signature
        """
        __params = self.__params
        for k, v in __params:
            __params[k] = Helper.unescape(v)
        concData = base64.b64encode('-'.join(str(x) for x in __params.values()).encode('utf-8'))
        privKey = self._getCnf().getPrivateKey()
        signature = Crypto.sign(concData, privKey, Defines.SIGNATURE_ALGO)

        return base64.b64encode(signature)
    def validate(self):
        """
    * Validate all set purchase details\n
    * @return boolean
    * @raises IPC_Exception
        """
        try:
            self._getCnf().validate()
        except Exception as ex:
            raise IPC_Exception(f'Invalid Config details: {ex}')

        if not Helper.versionCheck(self._getCnf().getVersion(), '1.4'):
            raise IPC_Exception('IPCVersion ' + self._getCnf().getVersion() + ' does not support IPCPreAuthorizationStatus method. Please use 1.4 or above.')

        return True
示例#13
0
    def validate(self):
        """
    * @return bool
    * @raises IPC_Exception
        """
        if self.getCardToken():
            return True

        if self.getCardNumber() == None or not Helper.isValidCardNumber(
                self.getCardNumber()):
            raise IPC_Exception('Invalid card number')

        if self.getCvc() == None or not Helper.isValidCVC(self.getCvc()):
            raise IPC_Exception('Invalid card CVC')

        if self.getExpMM() == None or not self.getExpMM().isnumeric() or int(
                self.getExpMM() or "") <= 0 or int(self.getExpMM() or "") > 12:
            raise IPC_Exception('Invalid card expire date (MM)')

        if self.getExpYY() == None or not self.getExpYY().isnumeric() or int(
                self.getExpYY() or "") < datetime.datetime.today().year:
            raise IPC_Exception('Invalid card expire date (YY)')

        return False
    def validate(self):
        """
    * Validate all set refund details\n
    * @return boolean
    * @raises IPC_Exception
        """
        try:
            self._getCnf().validate()
        except Exception as ex:
            raise IPC_Exception(f'Invalid Config details: {ex}')

        if self.getOutputFormat() == None or not Helper.isValidOutputFormat(
                self.getOutputFormat()):
            raise IPC_Exception('Invalid Output format')

        return True
    def validate(self, paymentParametersRequired):
        """
    * Validate all set customer details\n
    * @param string paymentParametersRequired\n
    * @return bool
    * @raises IPC_Exception
        """
        if paymentParametersRequired == Purchase.Purchase.PURCHASE_TYPE_FULL:

            if self.getFirstName() == None:
                raise IPC_Exception('Invalid First name')

            if self.getLastName() == None:
                raise IPC_Exception('Invalid Last name')

            if self.getEmail() == None or not Helper.isValidEmail(
                    self.getEmail()):
                raise IPC_Exception('Invalid Email')

        return True
    def validate(self):
        """
    * Validate all set purchase details\n
    * @return boolean
    * @raises IPC_Exception
        """
        if self.getUrlCancel() == None or not Helper.isValidURL(
                self.getUrlCancel()):
            raise IPC_Exception('Invalid Cancel URL')

        if self.getUrlNotify() == None or not Helper.isValidURL(
                self.getUrlNotify()):
            raise IPC_Exception('Invalid Notify URL')

        if self.getUrlOk() == None or not Helper.isValidURL(self.getUrlOk()):
            raise IPC_Exception('Invalid Success URL')

        if (self.getCardTokenRequest() == None
                or (not self.getCardTokenRequest() in [
                    self.CARD_TOKEN_REQUEST_NONE,
                    self.CARD_TOKEN_REQUEST_ONLY_STORE,
                    self.CARD_TOKEN_REQUEST_PAY_AND_STORE,
                ])):
            raise IPC_Exception(
                'Invalid value provided for CardTokenRequest params')

        if (self.getPaymentParametersRequired() == None
                or (not self.getPaymentParametersRequired() in [
                    self.PURCHASE_TYPE_FULL,
                    self.PURCHASE_TYPE_SIMPLIFIED_CALL,
                    self.PURCHASE_TYPE_SIMPLIFIED_PAYMENT_PAGE,
                ])):
            raise IPC_Exception(
                'Invalid value provided for PaymentParametersRequired params')

        if self.getCurrency() == None:
            raise IPC_Exception('Invalid currency')

        try:
            self._getCnf().validate()
        except Exception as ex:
            raise IPC_Exception(f'Invalid Config details: {ex}')

        if not self.__isNoCartPurchase():
            if self.getCart() == None:
                raise IPC_Exception('Missing Cart details')

            try:
                self.getCart().validate()
            except Exception as ex:
                raise IPC_Exception(f'Invalid Cart details: {ex}')

        if self.getPaymentParametersRequired() == self.PURCHASE_TYPE_FULL:
            try:
                if not self.getCustomer():
                    raise IPC_Exception('Customer details not set!')
                self.getCustomer().validate(
                    self.getPaymentParametersRequired())
            except Exception as ex:
                raise IPC_Exception(f'Invalid Customer details: {ex}')

        return True
 def __getSignData(self):
     return base64.b64encode('-'.join(
         list(Helper.getValuesFromMultiDimensionalArray(
             self.__data))).encode('utf-8'))