示例#1
0
文件: paypal.py 项目: RMLL/resarmll
 def confirm(self):
     qs = 'cmd=_notify-validate&'+self.datas.urlencode()
     uh = urllib2.urlopen(settings.PAYPAL_SETTINGS['url'], qs)
     check = uh.read().strip()
     uh.close()
     ret = check == 'VERIFIED'
     if not ret:
         send_admins(
             "PAYPAL FAIL - invalid code=[%s]" % (check),
             "resa/payment_fail_admin_email.txt",
             {'errors': '', 'env': self.env_datas(), 'dump': self.dump_datas()})
     return ret
示例#2
0
 def confirm(self):
     qs = 'cmd=_notify-validate&' + self.datas.urlencode()
     uh = urllib2.urlopen(settings.PAYPAL_SETTINGS['url'], qs)
     check = uh.read().strip()
     uh.close()
     ret = check == 'VERIFIED'
     if not ret:
         send_admins("PAYPAL FAIL - invalid code=[%s]" % (check),
                     "resa/payment_fail_admin_email.txt", {
                         'errors': '',
                         'env': self.env_datas(),
                         'dump': self.dump_datas()
                     })
     return ret
示例#3
0
    def process_order(self):
        error, code, params = self.getreturndatas()
        if error or not params:
            self.add_error(
                _(u"Error while receiving data from the bank: [%s]") % (code))
        else:
            try:
                order = Order.objects.get(id=int(params['order_id']))
            except:
                order = None
            if not order:
                self.add_error(
                    _(u"Unable to find order with id: #%d") % (order.id))
            elif order.payment_date != None:
                self.add_error(
                    _(u"Order with id: #%d has already been paid") %
                    (order.id))
            else:
                if params['bank_response_code'] != '00':
                    self.add_error(
                        _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                          ) % {
                              'arg1': 'bank_response_code',
                              'arg2': params['bank_response_code'],
                              'arg3': '00'
                          })
                if params['merchant_id'] != settings.CYBERPLUS_SETTINGS[
                        'merchant_id']:
                    self.add_error(
                        _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                          ) %
                        {
                            'arg1': 'merchant_id',
                            'arg2': params['merchant_id'],
                            'arg3': settings.CYBERPLUS_SETTINGS['merchant_id']
                        })
                if params['currency_code'] != settings.CYBERPLUS_SETTINGS[
                        'currency_code']:
                    self.add_error(
                        _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                          ) % {
                              'arg1': 'currency_code',
                              'arg2': params['currency_code'],
                              'arg3':
                              settings.CYBERPLUS_SETTINGS['currency_code']
                          })
                amount = dec(params['amount']) / 100
                if amount != order.totalamount():
                    self.add_error(
                        _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                          ) % {
                              'arg1': 'amount',
                              'arg2': amount,
                              'arg3': order.totalamount()
                          })

                if not self.has_errors():
                    try:
                        user = User.objects.get(id=order.user_id)
                    except:
                        user = None
                    if not user:
                        self.add_error(
                            _(u"Cannot find user associated to order no: #%d")
                            % (order.id))
                    else:
                        tax = dec(str(settings.COMPTA_BANK_FIXED_TAX)) + dec(
                            str(settings.COMPTA_BANK_VARIABLE_TAX)
                        ) * order.totalamount()
                        # mark order as paid
                        self.order_paid(order, tax, user,
                                        'ref:' + params['transaction_id'])

                        # mail info to admins
                        send_admins(
                            "CYBERPLUS OK - [order=%d] [amount=%.2f] [user=%s] [email=%s]"
                            % (order.id, order.totalamount(), user.id,
                               user.email),
                            "resa/payment_ok_bank_admin_email.txt", {
                                'order': order,
                                'currency': settings.CURRENCY,
                                'currency_alt': settings.CURRENCY_ALT,
                                'env': self.env_datas(),
                                'dump': params
                            })

                        # switch language before sending mail
                        translation.activate(user.get_profile().language)
                        # mail info to user
                        send_email(
                            [user.email],
                            _(u"Bank payment - order no #%d") % order.id,
                            "resa/payment_bank_email.txt", {
                                'order': order,
                                'currency': settings.CURRENCY,
                                'currency_alt': settings.CURRENCY_ALT
                            })

        if self.has_errors():
            send_admins(
                "CYBERPLUS FAIL", "resa/payment_fail_admin_email.txt", {
                    'errors': "\n".join(self.errors),
                    'env': self.env_datas(),
                    'dump': params
                })
示例#4
0
    def process_order(self):
        error, params = self.getreturndatas()
        if error or not params:
            self.add_error(_(u"Error while receiving data from the bank."))
        else:
            order_id = int(params['order'].split('-')[0])
            try:
                order = Order.objects.get(id=order_id)
            except:
                order = None
            if not order:
                self.add_error(
                    _(u"Unable to find order with id: #%d") % (order_id))
            elif order.payment_date != None:
                self.add_error(
                    _(u"Order with id: #%d has already been paid") %
                    (order.id))
            else:
                if params.has_key('autor') and params[
                        'autor'] == 'XXXXXX' and not settings.ETRANSACTIONS_SETTINGS[
                            'testmode']:
                    self.add_error(
                        _(u"Fictive payment received (AUTOR=%s)") %
                        (params['autor']))
                elif params['err'] != '00000' and ETRANSACTIONS_CODES.has_key(
                        params['err']):
                    self.add_error(
                        _(u"Payment error: %s") %
                        (ETRANSACTIONS_CODES[params['err']]))
                elif params['err'] == '00000':
                    # payment ok
                    pass
                else:
                    self.add_error(
                        _(u"Payment received with invalid error code: [%s]") %
                        (params['err']))

                amount = dec(params['amount']) / 100
                if amount != order.totalamount():
                    self.add_error(
                        _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                          ) % {
                              'arg1': 'amount',
                              'arg2': amount,
                              'arg3': order.totalamount()
                          })

                if not self.has_errors():
                    try:
                        user = User.objects.get(id=order.user_id)
                    except:
                        user = None
                    if not user:
                        self.add_error(
                            _(u"Cannot find user associated to order no: #%d")
                            % (order.id))
                    else:
                        tax = dec(str(settings.COMPTA_BANK_FIXED_TAX)) + dec(
                            str(settings.COMPTA_BANK_VARIABLE_TAX)
                        ) * order.totalamount()
                        ## mark order as paid
                        self.order_paid(
                            order, tax, user, 'ref: %s/%s' %
                            (params['idtrans'], params['numtrans']))

                        ## mail info to admins
                        send_admins(
                            "ETRANSACTIONS OK - [order=%d] [amount=%.2f] [user=%s] [email=%s]"
                            % (order.id, order.totalamount(), user.id,
                               user.email),
                            "resa/payment_ok_bank_admin_email.txt", {
                                'order': order,
                                'currency': settings.CURRENCY,
                                'currency_alt': settings.CURRENCY_ALT,
                                'env': self.env_datas(),
                                'dump': params
                            })

                        # switch language before sending mail
                        translation.activate(user.get_profile().language)
                        # mail info to user
                        send_email(
                            [user.email],
                            _(u"Bank payment - order no #%d") % order.id,
                            "resa/payment_bank_email.txt", {
                                'order': order,
                                'currency': settings.CURRENCY,
                                'currency_alt': settings.CURRENCY_ALT
                            })

        if self.has_errors():
            send_admins(
                "ETRANSACTIONS FAIL", "resa/payment_fail_admin_email.txt", {
                    'errors': "\n".join(self.errors),
                    'env': self.env_datas(),
                    'dump': params
                })
示例#5
0
    def process_order(self):
        order_id = self.order_id
        try:
            order = Order.objects.get(id=order_id)
        except:
            order = None

        if not order:
            self.add_error(
                _(u"Unable to find order with id: #%d") % (order_id))
        elif order.payment_date != None:
            self.add_error(
                _(u"Order with id: #%d has already been paid") % (order_id))
        else:
            status = self.datas.get('payment_status', '')
            email = self.datas.get('receiver_email', '')
            currency = self.datas.get('mc_currency', '')
            amount = dec(self.datas.get('mc_gross', 0))
            if status not in ['Completed', 'Pending']:
                self.add_error(
                    _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                      ) % {
                          'arg1': 'payment_status',
                          'arg2': status,
                          'arg3': 'Completed] or [Pending'
                      })
            if email != settings.PAYPAL_SETTINGS['id']:
                self.add_error(
                    _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                      ) % {
                          'arg1': 'receiver_email',
                          'arg2': email,
                          'arg3': settings.PAYPAL_SETTINGS['id']
                      })
            if currency != settings.PAYPAL_SETTINGS['currency']:
                self.add_error(
                    _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                      ) % {
                          'arg1': 'mc_currency',
                          'arg2': currency,
                          'arg3': settings.PAYPAL_SETTINGS['currency']
                      })
            if amount != order.totalamount():
                self.add_error(
                    _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                      ) % {
                          'arg1': 'mc_gross',
                          'arg2': amount,
                          'arg3': order.totalamount()
                      })

            if not self.has_errors():
                try:
                    user = User.objects.get(id=order.user_id)
                except:
                    user = None
                if not user:
                    self.add_error(
                        _(u"Cannot find user associated to order no: #%d") %
                        (order_id))
                else:
                    fee = dec(self.datas.get('mc_fee', 0))
                    # mark order as paid
                    self.order_paid(order, fee, user,
                                    'ref:' + self.datas.get('txn_id', ''))

                    # mail info to admins
                    send_admins(
                        "PAYPAL OK - [order=%d] [amount=%.2f] [user=%s] [email=%s]"
                        % (order_id, order.totalamount(), user.id, user.email),
                        "resa/payment_ok_paypal_admin_email.txt", {
                            'order': order,
                            'currency': settings.CURRENCY,
                            'currency_alt': settings.CURRENCY_ALT,
                            'env': self.env_datas(),
                            'dump': self.dump_datas()
                        })

                    # switch language before sending mail
                    translation.activate(user.get_profile().language)
                    # mail info to user
                    send_email(
                        [user.email],
                        _(u"PayPal payment - order no #%d") % order_id,
                        "resa/payment_paypal_email.txt", {
                            'order': order,
                            'currency': settings.CURRENCY,
                            'currency_alt': settings.CURRENCY_ALT
                        })

        if self.has_errors():
            send_admins(
                "PAYPAL FAIL", "resa/payment_fail_admin_email.txt", {
                    'errors': "\n".join(self.errors),
                    'env': self.env_datas(),
                    'dump': self.dump_datas()
                })
示例#6
0
文件: cmcic.py 项目: RMLL/resarmll
    def process_order(self):
        retcode = "version=2\ncdr=0\n"
        error, code, params = self.getreturndatas()
        if error:
            retcode = "version=2\ncdr=1\n"
        if error or not params:
            self.add_error(_(u"Error while receiving data from the bank: [%s]") % (code))
        else:
            try:
                order = Order.objects.get(id=int(params['order_id']))
            except:
                order = None
            if not order:
                self.add_error(_(u"Unable to find order with id: #%d") % (int(params['order_id'])))
            elif order.payment_date != None:
                self.add_error(_(u"Order with id: #%d has already been paid") % (order.id))
            else:
                if params['code-retour'] not in ['Annulation', 'paiement', 'payetest']:
                    self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                        {'arg1': 'code-retour', 'arg2': params['code-retour'], 'arg3': '\'Annulation\' or \'paiement\' or \'payetest\''})
                elif params['code-retour'] == 'payetest' and not settings.CMCIC_SETTINGS['testmode']:
                    self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                        {'arg1': 'code-retour', 'arg2': params['code-retour'], 'arg3': '\'Annulation\' or \'paiement\''})
                elif params['code-retour'] == 'Annulation':
                    self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                    {'arg1': 'code-retour', 'arg2': params['code-retour'], 'arg3': '\'paiement\''})
                if params['TPE'] != settings.CMCIC_SETTINGS['tpe']:
                    self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                        {'arg1': 'TPE', 'arg2': params['TPE'], 'arg3': settings.CMCIC_SETTINGS['tpe']})
                if params['devise'] != settings.CMCIC_SETTINGS['devise']:
                    self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                        {'arg1': 'devise', 'arg2': params['devise'], 'arg3': settings.CMCIC_SETTINGS['devise']})
                amount = dec(params['amount'])
                if amount != order.totalamount():
                    self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                        {'arg1': 'amount', 'arg2': amount, 'arg3': order.totalamount()})
                if not self.has_errors():
                    try:
                        user = User.objects.get(id=order.user_id)
                    except:
                        user = None
                    if not user:
                        self.add_error(_(u"Cannot find user associated to order no: #%d") % (order.id))
                    else:
                        tax = dec(str(settings.COMPTA_BANK_FIXED_TAX)) + dec(str(settings.COMPTA_BANK_VARIABLE_TAX))*order.totalamount()
                        # mark order as paid
                        self.order_paid(order, tax, user, 'ref:'+params['numauto'])

                        # mail info to admins
                        send_admins(
                            "CMCIC OK - [order=%d] [amount=%.2f] [user=%s] [email=%s]" %
                                (order.id, order.totalamount(), user.id, user.email),
                                "resa/payment_ok_bank_admin_email.txt",
                                {'order': order,
                                'currency': settings.CURRENCY, 'currency_alt': settings.CURRENCY_ALT,
                                'env': self.env_datas(), 'dump': params})

                        # switch language before sending mail
                        translation.activate(user.get_profile().language)
                        # mail info to user
                        send_email([user.email], _(u"Bank payment - order no #%d") % order.id,
                            "resa/payment_bank_email.txt",
                            {'order': order, 'currency': settings.CURRENCY, 'currency_alt': settings.CURRENCY_ALT})

        if self.has_errors():
            send_admins(
                "CMCIC FAIL",
                "resa/payment_fail_admin_email.txt",
                {'errors': "\n".join(self.errors),
                'env': self.env_datas(), 'dump': params})

        return retcode
示例#7
0
    def process_order(self):
        retcode = "version=2\ncdr=0\n"
        error, code, params = self.getreturndatas()
        if error:
            retcode = "version=2\ncdr=1\n"
        if error or not params:
            self.add_error(
                _(u"Error while receiving data from the bank: [%s]") % (code))
        else:
            try:
                order = Order.objects.get(id=int(params['order_id']))
            except:
                order = None
            if not order:
                self.add_error(
                    _(u"Unable to find order with id: #%d") %
                    (int(params['order_id'])))
            elif order.payment_date != None:
                self.add_error(
                    _(u"Order with id: #%d has already been paid") %
                    (order.id))
            else:
                if params['code-retour'] not in [
                        'Annulation', 'paiement', 'payetest'
                ]:
                    self.add_error(
                        _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                          ) % {
                              'arg1':
                              'code-retour',
                              'arg2':
                              params['code-retour'],
                              'arg3':
                              '\'Annulation\' or \'paiement\' or \'payetest\''
                          })
                elif params[
                        'code-retour'] == 'payetest' and not settings.CMCIC_SETTINGS[
                            'testmode']:
                    self.add_error(
                        _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                          ) % {
                              'arg1': 'code-retour',
                              'arg2': params['code-retour'],
                              'arg3': '\'Annulation\' or \'paiement\''
                          })
                elif params['code-retour'] == 'Annulation':
                    self.add_error(
                        _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                          ) % {
                              'arg1': 'code-retour',
                              'arg2': params['code-retour'],
                              'arg3': '\'paiement\''
                          })
                if params['TPE'] != settings.CMCIC_SETTINGS['tpe']:
                    self.add_error(
                        _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                          ) % {
                              'arg1': 'TPE',
                              'arg2': params['TPE'],
                              'arg3': settings.CMCIC_SETTINGS['tpe']
                          })
                if params['devise'] != settings.CMCIC_SETTINGS['devise']:
                    self.add_error(
                        _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                          ) % {
                              'arg1': 'devise',
                              'arg2': params['devise'],
                              'arg3': settings.CMCIC_SETTINGS['devise']
                          })
                amount = dec(params['amount'])
                if amount != order.totalamount():
                    self.add_error(
                        _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                          ) % {
                              'arg1': 'amount',
                              'arg2': amount,
                              'arg3': order.totalamount()
                          })
                if not self.has_errors():
                    try:
                        user = User.objects.get(id=order.user_id)
                    except:
                        user = None
                    if not user:
                        self.add_error(
                            _(u"Cannot find user associated to order no: #%d")
                            % (order.id))
                    else:
                        tax = dec(str(settings.COMPTA_BANK_FIXED_TAX)) + dec(
                            str(settings.COMPTA_BANK_VARIABLE_TAX)
                        ) * order.totalamount()
                        # mark order as paid
                        self.order_paid(order, tax, user,
                                        'ref:' + params['numauto'])

                        # mail info to admins
                        send_admins(
                            "CMCIC OK - [order=%d] [amount=%.2f] [user=%s] [email=%s]"
                            % (order.id, order.totalamount(), user.id,
                               user.email),
                            "resa/payment_ok_bank_admin_email.txt", {
                                'order': order,
                                'currency': settings.CURRENCY,
                                'currency_alt': settings.CURRENCY_ALT,
                                'env': self.env_datas(),
                                'dump': params
                            })

                        # switch language before sending mail
                        translation.activate(user.get_profile().language)
                        # mail info to user
                        send_email(
                            [user.email],
                            _(u"Bank payment - order no #%d") % order.id,
                            "resa/payment_bank_email.txt", {
                                'order': order,
                                'currency': settings.CURRENCY,
                                'currency_alt': settings.CURRENCY_ALT
                            })

        if self.has_errors():
            send_admins(
                "CMCIC FAIL", "resa/payment_fail_admin_email.txt", {
                    'errors': "\n".join(self.errors),
                    'env': self.env_datas(),
                    'dump': params
                })

        return retcode
示例#8
0
    def process_order(self):
        error, params = self.getreturndatas()
        if error or not params:
            self.add_error(_(u"Error while receiving data from the bank."))
        else:
            order_id = int(params['order'].split('-')[0])
            try:
                order = Order.objects.get(id=order_id)
            except:
                order = None
            if not order:
                self.add_error(_(u"Unable to find order with id: #%d") % (order_id))
            elif order.payment_date != None:
                self.add_error(_(u"Order with id: #%d has already been paid") % (order.id))
            else:
                if params.has_key('autor') and params['autor'] == 'XXXXXX' and not settings.ETRANSACTIONS_SETTINGS['testmode']:
                    self.add_error(_(u"Fictive payment received (AUTOR=%s)") % (params['autor']))
                elif params['err'] != '00000' and ETRANSACTIONS_CODES.has_key(params['err']):
                    self.add_error(_(u"Payment error: %s") % (ETRANSACTIONS_CODES[params['err']]))
                elif params['err'] == '00000':
                    # payment ok
                    pass
                else:
                    self.add_error(_(u"Payment received with invalid error code: [%s]") % (params['err']))

                amount = dec(params['amount']) / 100
                if amount != order.totalamount():
                    self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                        {'arg1': 'amount', 'arg2': amount, 'arg3': order.totalamount()})

                if not self.has_errors():
                    try:
                        user = User.objects.get(id=order.user_id)
                    except:
                        user = None
                    if not user:
                        self.add_error(_(u"Cannot find user associated to order no: #%d") % (order.id))
                    else:
                        tax = dec(str(settings.COMPTA_BANK_FIXED_TAX)) + dec(str(settings.COMPTA_BANK_VARIABLE_TAX))*order.totalamount()
                        ## mark order as paid
                        self.order_paid(order, tax, user, 'ref: %s/%s' % (params['idtrans'], params['numtrans']))

                        ## mail info to admins
                        send_admins(
                            "ETRANSACTIONS OK - [order=%d] [amount=%.2f] [user=%s] [email=%s]" %
                                (order.id, order.totalamount(), user.id, user.email),
                                "resa/payment_ok_bank_admin_email.txt",
                                {'order': order,
                                'currency': settings.CURRENCY, 'currency_alt': settings.CURRENCY_ALT,
                                'env': self.env_datas(), 'dump': params})

                        # switch language before sending mail
                        translation.activate(user.get_profile().language)
                        # mail info to user
                        send_email([user.email], _(u"Bank payment - order no #%d") % order.id,
                            "resa/payment_bank_email.txt",
                            {'order': order, 'currency': settings.CURRENCY, 'currency_alt': settings.CURRENCY_ALT})

        if self.has_errors():
            send_admins(
                "ETRANSACTIONS FAIL",
                "resa/payment_fail_admin_email.txt",
                {'errors': "\n".join(self.errors),
                'env': self.env_datas(), 'dump': params})
示例#9
0
文件: ogone.py 项目: RMLL/resarmll
    def process_order(self):
        retcode = "OK"
        error, code, params = self.getreturndatas()
        
        if error or not params:
            self.add_error(_(u"Error while receiving data from the bank: [%s]") % (code))
        else:
            try:
                order = Order.objects.get(id=int(params['ORDER_ID']))
            except:
                order = None
            if not order:
                self.add_error(_(u"Unable to find order with id: #%d") % (int(params['ORDER_ID'])))
            elif order.payment_date != None:
                self.add_error(_(u"Order with id: #%d has already been paid") % (order.id))
            else:
                if params['STATUS'] not in ['5', '51', '9', '91']:
                    self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                        {'arg1': 'STATUS', 'arg2': params['STATUS'], 'arg3': '5,51,9,91'})
                if params['ACCEPTANCE'].find('test') >= 0 and not settings.OGONE_SETTINGS['testmode']:
                    self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                        {'arg1': 'ACCEPTANCE', 'arg2': params['ACCEPTANCE'], 'arg3': '/\d+/'})
                if params['NCERROR'] not in ['0']:
                    self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                        {'arg1': 'NCERROR', 'arg2': params['NCERROR'], 'arg3': '0'})
                if params['CURRENCY'] != settings.OGONE_SETTINGS['currency']:
                    self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                        {'arg1': 'CURRENCY', 'arg2': params['CURRENCY'], 'arg3': settings.OGONE_SETTINGS['currency']})
                amount = Decimal(params['AMOUNT'])
                
                if amount != order.totalamount():
                    self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                        {'arg1': 'AMOUNT', 'arg2': amount, 'arg3': order.totalamount()})
                if not self.has_errors():
                    try:
                        user = User.objects.get(id=order.user_id)
                    except:
                        user = None
                    if not user:
                        self.add_error(_(u"Cannot find user associated to order no: #%d") % (order.id))
                    else:
                        tax = Decimal(str(settings.COMPTA_BANK_FIXED_TAX)) + Decimal(str(settings.COMPTA_BANK_VARIABLE_TAX))*order.totalamount()
                        # mark order as paid
                        self.order_paid(order, tax, user, 'ref:'+params['PAYID'])

                        # mail info to admins
                        send_admins(
                            "OGONE OK - [order=%d] [amount=%.2f] [user=%s] [email=%s]" %
                                (order.id, order.totalamount(), user.id, user.email),
                                "resa/payment_ok_bank_admin_email.txt",
                                {'order': order,
                                'currency': settings.CURRENCY, 'currency_alt': settings.CURRENCY_ALT,
                                'env': self.env_datas(), 'dump': params})

                        # switch language before sending mail
                        translation.activate(user.get_profile().language)
                        # mail info to user
                        send_email([user.email], _(u"Bank payment - order no #%d") % order.id,
                            "resa/payment_bank_email.txt",
                            {'order': order, 'currency': settings.CURRENCY, 'currency_alt': settings.CURRENCY_ALT})

        if self.has_errors():
            send_admins(
                "OGONE FAIL",
                "resa/payment_fail_admin_email.txt",
                {'errors': "\n".join(self.errors),
                'env': self.env_datas(), 'dump': params})

        if error or self.has_errors():
            retcode = "KO"
        
        return retcode
示例#10
0
文件: paypal.py 项目: RMLL/resarmll
    def process_order(self):
        order_id = self.order_id
        try:
            order = Order.objects.get(id=order_id)
        except:
            order = None

        if not order:
            self.add_error(_(u"Unable to find order with id: #%d") % (order_id))
        elif order.payment_date != None:
            self.add_error(_(u"Order with id: #%d has already been paid") % (order_id))
        else:
            status = self.datas.get('payment_status', '')
            email = self.datas.get('receiver_email', '')
            currency = self.datas.get('mc_currency', '')
            amount = dec(self.datas.get('mc_gross', 0))
            if status not in ['Completed', 'Pending']:
                self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                    {'arg1': 'payment_status', 'arg2': status, 'arg3': 'Completed] or [Pending'})
            if email != settings.PAYPAL_SETTINGS['id']:
                self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                    {'arg1': 'receiver_email', 'arg2': email, 'arg3': settings.PAYPAL_SETTINGS['id']})
            if currency != settings.PAYPAL_SETTINGS['currency']:
                self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                    {'arg1': 'mc_currency', 'arg2': currency, 'arg3': settings.PAYPAL_SETTINGS['currency']})
            if amount != order.totalamount():
                self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                    {'arg1': 'mc_gross', 'arg2': amount, 'arg3': order.totalamount()})

            if not self.has_errors():
                try:
                    user = User.objects.get(id=order.user_id)
                except:
                    user = None
                if not user:
                    self.add_error(_(u"Cannot find user associated to order no: #%d") % (order_id))
                else:
                    fee = dec(self.datas.get('mc_fee', 0))
                    # mark order as paid
                    self.order_paid(order, fee, user, 'ref:'+self.datas.get('txn_id', ''))

                    # mail info to admins
                    send_admins(
                        "PAYPAL OK - [order=%d] [amount=%.2f] [user=%s] [email=%s]" %
                            (order_id, order.totalamount(), user.id, user.email),
                        "resa/payment_ok_paypal_admin_email.txt",
                        {'order': order,
                        'currency': settings.CURRENCY, 'currency_alt': settings.CURRENCY_ALT,
                        'env': self.env_datas(), 'dump': self.dump_datas()})

                    # switch language before sending mail
                    translation.activate(user.get_profile().language)
                    # mail info to user
                    send_email([user.email], _(u"PayPal payment - order no #%d") % order_id,
                        "resa/payment_paypal_email.txt",
                        {'order': order, 'currency': settings.CURRENCY, 'currency_alt': settings.CURRENCY_ALT})

        if self.has_errors():
            send_admins(
                "PAYPAL FAIL",
                "resa/payment_fail_admin_email.txt",
                {'errors': "\n".join(self.errors),
                'env': self.env_datas(), 'dump': self.dump_datas()})
示例#11
0
    def process_order(self):
        retcode = "OK"
        error, code, params = self.getreturndatas()

        if error or not params:
            self.add_error(
                _(u"Error while receiving data from the bank: [%s]") % (code))
        else:
            try:
                order = Order.objects.get(id=int(params['ORDER_ID']))
            except:
                order = None
            if not order:
                self.add_error(
                    _(u"Unable to find order with id: #%d") %
                    (int(params['ORDER_ID'])))
            elif order.payment_date != None:
                self.add_error(
                    _(u"Order with id: #%d has already been paid") %
                    (order.id))
            else:
                if params['STATUS'] not in ['5', '51', '9', '91']:
                    self.add_error(
                        _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                          ) % {
                              'arg1': 'STATUS',
                              'arg2': params['STATUS'],
                              'arg3': '5,51,9,91'
                          })
                if params['ACCEPTANCE'].find(
                        'test'
                ) >= 0 and not settings.OGONE_SETTINGS['testmode']:
                    self.add_error(
                        _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                          ) % {
                              'arg1': 'ACCEPTANCE',
                              'arg2': params['ACCEPTANCE'],
                              'arg3': '/\d+/'
                          })
                if params['NCERROR'] not in ['0']:
                    self.add_error(
                        _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                          ) % {
                              'arg1': 'NCERROR',
                              'arg2': params['NCERROR'],
                              'arg3': '0'
                          })
                if params['CURRENCY'] != settings.OGONE_SETTINGS['currency']:
                    self.add_error(
                        _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                          ) % {
                              'arg1': 'CURRENCY',
                              'arg2': params['CURRENCY'],
                              'arg3': settings.OGONE_SETTINGS['currency']
                          })
                amount = Decimal(params['AMOUNT'])

                if amount != order.totalamount():
                    self.add_error(
                        _(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]"
                          ) % {
                              'arg1': 'AMOUNT',
                              'arg2': amount,
                              'arg3': order.totalamount()
                          })
                if not self.has_errors():
                    try:
                        user = User.objects.get(id=order.user_id)
                    except:
                        user = None
                    if not user:
                        self.add_error(
                            _(u"Cannot find user associated to order no: #%d")
                            % (order.id))
                    else:
                        tax = Decimal(str(
                            settings.COMPTA_BANK_FIXED_TAX)) + Decimal(
                                str(settings.COMPTA_BANK_VARIABLE_TAX)
                            ) * order.totalamount()
                        # mark order as paid
                        self.order_paid(order, tax, user,
                                        'ref:' + params['PAYID'])

                        # mail info to admins
                        send_admins(
                            "OGONE OK - [order=%d] [amount=%.2f] [user=%s] [email=%s]"
                            % (order.id, order.totalamount(), user.id,
                               user.email),
                            "resa/payment_ok_bank_admin_email.txt", {
                                'order': order,
                                'currency': settings.CURRENCY,
                                'currency_alt': settings.CURRENCY_ALT,
                                'env': self.env_datas(),
                                'dump': params
                            })

                        # switch language before sending mail
                        translation.activate(user.get_profile().language)
                        # mail info to user
                        send_email(
                            [user.email],
                            _(u"Bank payment - order no #%d") % order.id,
                            "resa/payment_bank_email.txt", {
                                'order': order,
                                'currency': settings.CURRENCY,
                                'currency_alt': settings.CURRENCY_ALT
                            })

        if self.has_errors():
            send_admins(
                "OGONE FAIL", "resa/payment_fail_admin_email.txt", {
                    'errors': "\n".join(self.errors),
                    'env': self.env_datas(),
                    'dump': params
                })

        if error or self.has_errors():
            retcode = "KO"

        return retcode
示例#12
0
    def process_order(self):
        error, code, params = self.getreturndatas()
        if error or not params:
            self.add_error(_(u"Error while receiving data from the bank: [%s]") % (code))
        else:
            try:
                order = Order.objects.get(id=int(params['order_id']))
            except:
                order = None
            if not order:
                self.add_error(_(u"Unable to find order with id: #%d") % (order.id))
            elif order.payment_date != None:
                self.add_error(_(u"Order with id: #%d has already been paid") % (order.id))
            else:
                if params['bank_response_code'] != '00':
                    self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                        {'arg1': 'bank_response_code', 'arg2': params['bank_response_code'], 'arg3': '00'})
                if params['merchant_id'] != settings.CYBERPLUS_SETTINGS['merchant_id']:
                    self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                        {'arg1': 'merchant_id', 'arg2': params['merchant_id'], 'arg3': settings.CYBERPLUS_SETTINGS['merchant_id']})
                if params['currency_code'] != settings.CYBERPLUS_SETTINGS['currency_code']:
                    self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                        {'arg1': 'currency_code', 'arg2': params['currency_code'], 'arg3': settings.CYBERPLUS_SETTINGS['currency_code']})
                amount = dec(params['amount']) / 100
                if amount != order.totalamount():
                    self.add_error(_(u"Wrong parameter '%(arg1)s': [%(arg2)s] instead of [%(arg3)s]") %
                        {'arg1': 'amount', 'arg2': amount, 'arg3': order.totalamount()})

                if not self.has_errors():
                    try:
                        user = User.objects.get(id=order.user_id)
                    except:
                        user = None
                    if not user:
                        self.add_error(_(u"Cannot find user associated to order no: #%d") % (order.id))
                    else:
                        tax = dec(str(settings.COMPTA_BANK_FIXED_TAX)) + dec(str(settings.COMPTA_BANK_VARIABLE_TAX))*order.totalamount()
                        # mark order as paid
                        self.order_paid(order, tax, user, 'ref:'+params['transaction_id'])

                        # mail info to admins
                        send_admins(
                            "CYBERPLUS OK - [order=%d] [amount=%.2f] [user=%s] [email=%s]" %
                                (order.id, order.totalamount(), user.id, user.email),
                                "resa/payment_ok_bank_admin_email.txt",
                                {'order': order,
                                'currency': settings.CURRENCY, 'currency_alt': settings.CURRENCY_ALT,
                                'env': self.env_datas(), 'dump': params})

                        # switch language before sending mail
                        translation.activate(user.get_profile().language)
                        # mail info to user
                        send_email([user.email], _(u"Bank payment - order no #%d") % order.id,
                            "resa/payment_bank_email.txt",
                            {'order': order, 'currency': settings.CURRENCY, 'currency_alt': settings.CURRENCY_ALT})

        if self.has_errors():
            send_admins(
                "CYBERPLUS FAIL",
                "resa/payment_fail_admin_email.txt",
                {'errors': "\n".join(self.errors),
                'env': self.env_datas(), 'dump': params})