Example #1
0
 'email':
 user.email,
 'first_name':
 user.first_name.encode('utf-8'),
 'last_name':
 user.last_name.encode('utf-8'),
 'connector':
 user.usersettings.popup_reaction,
 'monthly_updates':
 user.usersettings.monthly_updates,
 'verified':
 user.has_usable_password(),
 'balance (C)':
 ocuser.get_balance_available(),
 'balance ($)':
 ocuser.get_balance_available_usd(),
 'has_bonus':
 ocledger.has_bonus(user.userentity),
 'redemptions (approved)':
 len(redemptions_app),
 'date first redemption approved':
 redemptions_app[-1].date_created.strftime('%m/%d/%Y')
 if redemptions_app else None,
 'date last redemption approved':
 redemptions_app[0].date_created.strftime('%m/%d/%Y')
 if redemptions_app else None,
 'redemptions (pending)':
 len(redemptions_req),
 'date first redemption pending':
 redemptions_req[-1].date_created.strftime('%m/%d/%Y')
 if redemptions_req else None,
Example #2
0
    def save(self, *args, **kwargs):
        super(TransactionAction, self).save(*args, **kwargs)

        from openCurrents.interfaces.ocuser import OcUser

        # check if the transaction action for selected transaction exists
        tr = self.transaction
        bizname = tr.biz_name if tr.biz_name else tr.offer.org.name

        # common transaction action email data
        email_vars = [{
            'name': 'ORG_NAME',
            'content': bizname
        }, {
            'name': 'AMOUNT',
            'content': '%.2f' % tr.price_reported
        }, {
            'name': 'TRANSACTION_ID',
            'content': str(tr.id)
        }, {
            'name': 'FNAME',
            'content': tr.user.first_name
        }, {
            'name': 'LNAME',
            'content': tr.user.last_name
        }, {
            'name': 'USER_EMAIL',
            'content': tr.user.email
        }]
        template_name = None

        if self.action_type == 'req' and tr.offer.offer_type == 'gft':
            # send gift card out of stock email to bizdev
            sendTransactionalEmailBizDev('add-gift-card', email_vars)

            # merge vars and template name
            # for gift card out of stock to user
            template_name = 'gift-card-pending'

        elif self.action_type == 'app':
            oc_user = OcUser(tr.user.id)

            # transact cur from user to org
            Ledger.objects.create(entity_from=tr.user.userentity,
                                  entity_to=tr.offer.org.orgentity,
                                  currency='cur',
                                  amount=tr.currents_amount,
                                  transaction=self)

            # for cashback transactions, fiat ledger rec and confirmation email
            if tr.offer.offer_type == 'cbk':
                usd_amount = convert.cur_to_usd(tr.currents_amount, True)

                # transact usd from oC to user
                Ledger.objects.create(entity_from=OrgEntity.objects.get(
                    org__name='openCurrents'),
                                      entity_to=tr.user.userentity,
                                      currency='usd',
                                      amount=usd_amount,
                                      transaction=self)

                # merge vars and template name
                # for cashback transaction approved email to user
                template_name = 'transaction-approved'
                amount_usd = '%.2f' % float(usd_amount)
                amound_cur = '%.2f' % float(tr.currents_amount)
                balance_cur = '%.2f' % float(oc_user.get_balance_available())
                balance_usd = '%.2f' % float(
                    oc_user.get_balance_available_usd())
                email_vars = [{
                    'name': 'BIZ_NAME',
                    'content': bizname
                }, {
                    'name': 'DOLLARS_REDEEMED',
                    'content': amount_usd
                }, {
                    'name': 'CURRENTS_REDEEMED',
                    'content': amound_cur
                }, {
                    'name': 'CURRENTS_AVAILABLE',
                    'content': balance_cur
                }, {
                    'name': 'DOLLARS_AVAILABLE',
                    'content': balance_usd
                }]
            elif tr.offer.offer_type == 'gft':
                if not self.giftcard:
                    raise Exception(
                        'Approved action must be linked to a gift card')

                if self.giftcard.is_redeemed:
                    raise Exception('Gift card has already been redeemed')
                else:
                    self.giftcard.is_redeemed = True
                    self.giftcard.save()

                sendTransactionalEmailBizDev('gift-card-purchased', email_vars)

                # merge vars and template name
                # for giftcard email to user
                email_vars.extend([{
                    'name': 'CODE',
                    'content': self.giftcard.code
                }, {
                    'name': 'GIFT_IMAGE_URL',
                    'content': self.giftcard.image.url
                }])
                template_name = 'gift-card'

        # send transaction action email to user
        if template_name:
            sendTransactionalEmailUser(template_name, email_vars,
                                       tr.user.email)