示例#1
0
def test_ipn_is_transaction_duplicated(txn_id, payment_status, expected):
    request.form = {'payment_status': 'Completed', 'txn_id': '12345'}
    rh = RHPaypalIPN()
    rh.registration = MagicMock()
    rh.registration.transaction = None
    assert not rh._is_transaction_duplicated()
    transaction = PaymentTransaction(provider='paypal',
                                     data={
                                         'payment_status': payment_status,
                                         'txn_id': txn_id
                                     })
    rh.registration.transaction = transaction
    assert rh._is_transaction_duplicated() == expected
示例#2
0
    def migrate_transactions(self):
        self.messages.append(cformat("%{magenta!} - Payment Transactions:"))
        print cformat("%{white!}migrating payment transactions")

        count = 0
        errors = 0
        warnings = 0

        for event, registrant, transaction in committing_iterator(self._iter_transactions()):
            try:
                data = self._get_transaction_data(transaction, event)
            except ValueError as e:
                print cformat("%{red!}{0} (evt: {1}, reg: {2})").format(e, event.id, registrant._id)
                errors += 1
                continue

            if data['provider'] == '_manual' and data['amount'] == 0.0:
                print cformat("%{yellow!}Skipping {0[provider]} transaction (evt: {1}, reg: {2}) "
                              "with zero amount: {0[amount]} {0[currency]}").format(data, event.id, registrant._id)
                warnings += 1
                continue

            elif data['amount'] < 0.0:
                print cformat("%{yellow!}Skipping {0[provider]} transaction (evt: {1}, reg: {2}) "
                              "with negative amount: {0[amount]} {0[currency]}").format(data, event.id, registrant._id)
                warnings += 1
                continue

            pt = PaymentTransaction(event_id=int(event.id), registrant_id=int(registrant._id),
                                    status=TransactionStatus.successful, **data)

            count += 1
            print cformat("%{cyan}{0}").format(pt)
            db.session.add(pt)

        if warnings:
            warning_msg = cformat("%{yellow!}There were {0} warnings during the migration "
                                  "of the payment transactions.").format(warnings)
            self.messages.append('    ' + warning_msg)
            print warning_msg

        if errors:
            msg = cformat("%{red!}There were some errors during the migration of the payment transactions.\n"
                          "{0} transactions were not migrated and will be lost.\n").format(errors)
        else:
            msg = cformat("%{green!}migration of {0} payment transactions successful\n").format(count)
        self.messages.append('    ' + '\n    '.join(msg.split('\n')))
        print msg
示例#3
0
 def _create_transaction(status, **params):
     params.setdefault('amount', 10)
     params.setdefault('currency', 'USD')
     params.setdefault('provider', '_manual')
     params.setdefault('data', {})
     return PaymentTransaction(status=status, **params)