コード例 #1
0
ファイル: ipn.py プロジェクト: airtonix/django-shop-paypal
 def __init__(self, shop):
     self.shop = shop
     # Hook the payment was successful listener on the appropriate signal sent
     # by django-paypal (success_signal)
     assert settings.PAYPAL_RECEIVER_EMAIL, "You need to define a PAYPAL_RECEIVER_EMAIL in settings with the money recipient's email addresss"
     assert settings.PAYPAL_CURRENCY_CODE, "You need to define a PAYPAL_CURRENCY_CODE in settings with the currency code"
     success_signal.connect(self.payment_was_successful, weak=False)
     flagged_signal.connect(self.payment_was_flagged, weak=False)
     subscription_cancel_signal.connect(self.subscription_cancelled, weak=False)
     subscription_eot_signal.connect(self.subscription_expired, weak=False)
     subscription_modify_signal.connect(self.subscription_modified, weak=False)
     subscription_signup_signal.connect(self.subscription_signup_success, weak=False)
     recurring_create_signal.connect(self.recurring_created, weak=False)
     recurring_payment_signal.connect(self.recurring_payment, weak=False)
     recurring_cancel_signal.connect(self.recurring_cancelled, weak=False)
コード例 #2
0
ファイル: tiers.py プロジェクト: MechanisM/mirocommunity
    if ipn_obj.flag:
        return

    # If the IPN object refers to a subscription ID other than the one that is ours,
    # stop immediately. This could happen if, say, they create a new subscription ID
    # (due to upgrading tier) and then cancelling the old one.
    #
    # That's exactly how we ask people to upgrade between tiers. Luckily, this
    # transition case is covered by the test suite.
    tier_info = TierInfo.objects.get_current()
    if tier_info.current_paypal_profile_id != ipn_obj.subscr_id:
        return

    _actually_switch_tier('basic')
subscription_cancel.connect(on_subscription_cancel_switch_to_basic)
subscription_eot.connect(on_subscription_cancel_switch_to_basic)


def handle_recurring_profile_modify(sender, **kwargs):
    ipn_obj = sender

    # If the thing is invalid, do not process any further.
    if ipn_obj.flag:
        return

    sitelocation = SiteLocation.objects.get_current()
    tier_info = TierInfo.objects.get_current()

    if (tier_info.current_paypal_profile_id != sender.subscr_id) and (tier_info.use_zendesk()):
        # then we had better notify staff indicating that the old one
        # should be cancelled.
コード例 #3
0
            us.cancelled = True
            us.save()
            Transaction(user=u, subscription=s, ipn=sender,
                        event='cancel subscription', amount=sender.mc_gross
                        ).save()
        signals.unsubscribed.send(s, ipn=sender, subscription=s, user=u,
                                  usersubscription=us,
#                                  refund=refund, reason='cancel')
                                  reason='cancel')
    else:
        Transaction(user=u, subscription=s, ipn=sender,
                    event='unexpected cancel', amount=sender.mc_gross
                    ).save()
        signals.event.send(s, ipn=sender, subscription=s, user=u, event='unexpected_cancel')
subscription_cancel.connect(handle_subscription_cancel)
subscription_eot.connect(handle_subscription_cancel)

def handle_subscription_modify(sender, **kwargs):
    us = _ipn_usersubscription(sender)
    u, s = us.user, us.subscription
    print 'modify', u, s
    if us:
        # delete all user's other subscriptions
        for old_us in u.usersubscription_set.all():
            if old_us==us: continue     # don't touch current subscription
            old_us.delete()
            Transaction(user=u, subscription=s, ipn=sender,
                        event='remove subscription (deactivated)', amount=sender.mc_gross
                        ).save()

        # activate new subscription
コード例 #4
0
        subject, from_email = 'DA admin - Paypal subscription error', 'Directo al Artista <*****@*****.**>'
        message = render_to_string('email/paypal_subs_error.html', {
            'trans': trans,
            'object': ipn_obj.item_name,
        })

        html_content = render_to_string(
            'email/global/template.html', {
                'email_title': 'DA admin - Paypal subscription error',
                'email_content': message,
            })

        html_content = transform(html_content)
        text_content = strip_tags(html_content)

        msg = EmailMultiAlternatives(subject, text_content, from_email,
                                     ['*****@*****.**'])
        msg.attach_alternative(html_content, "text/html")
        msg.send(fail_silently=True)

    return valid


payment_was_successful.connect(payment_success)
payment_was_flagged.connect(payment_success_flagged)
payment_was_refunded.connect(paypal_refund_payment)

subscription_cancel.connect(paypal_subscription_canceled)
subscription_signup.connect(paypal_validate_plan_signup)
subscription_eot.connect(paypal_subscription_eot)
コード例 #5
0
ファイル: tiers.py プロジェクト: kmshi/Miro-Community
    # If the IPN object refers to a subscription ID other than the one that is ours,
    # stop immediately. This could happen if, say, they create a new subscription ID
    # (due to upgrading tier) and then cancelling the old one.
    #
    # That's exactly how we ask people to upgrade between tiers. Luckily, this
    # transition case is covered by the test suite.
    import localtv.models
    tier_info = localtv.models.TierInfo.objects.get_current()
    if tier_info.current_paypal_profile_id != ipn_obj.subscr_id:
        return

    _actually_switch_tier('basic')

subscription_cancel.connect(on_subscription_cancel_switch_to_basic)
subscription_eot.connect(on_subscription_cancel_switch_to_basic)

def handle_recurring_profile_modify(sender, **kwargs):
    ipn_obj = sender

    # If the thing is invalid, do not process any further.
    if ipn_obj.flag:
        return

    import localtv.models
    tier_info = localtv.models.TierInfo.objects.get_current()

    if (tier_info.current_paypal_profile_id != sender.subscr_id) and (tier_info.use_zendesk()):
        # then we had better notify staff indicating that the old one
        # should be cancelled.
        import localtv.zendesk
コード例 #6
0
    elif ipn_obj.mc_amount3 != trans.gross_amount:
        valid = False

    if not valid:
        subject, from_email = 'DA admin - Paypal subscription error', 'Directo al Artista <*****@*****.**>'
        message = render_to_string('email/paypal_subs_error.html', {
            'trans': trans, 'object': ipn_obj.item_name,
        })

        html_content = render_to_string('email/global/template.html', {
            'email_title': 'DA admin - Paypal subscription error',
            'email_content': message,
        })

        html_content = transform(html_content)
        text_content = strip_tags(html_content)

        msg = EmailMultiAlternatives(subject, text_content, from_email, ['*****@*****.**'])
        msg.attach_alternative(html_content, "text/html")
        msg.send(fail_silently=True)

    return valid

payment_was_successful.connect(payment_success)
payment_was_flagged.connect(payment_success_flagged)
payment_was_refunded.connect(paypal_refund_payment)

subscription_cancel.connect(paypal_subscription_canceled)
subscription_signup.connect(paypal_validate_plan_signup)
subscription_eot.connect(paypal_subscription_eot)
コード例 #7
0
ファイル: models.py プロジェクト: nelsonmonteiro/diagnose
		# TODO: Only setup for monthly based, need to cater for other cycles
		invalid_date = True
		day_start = self.created.day
		while invalid_date:
			try:
				if datetime.now().month == 12:
					next_cycle_reset = date(datetime.now().year+1, 1, day_start)
				else:
					next_cycle_reset = date(datetime.now().year, datetime.now().month+1, day_start)
				invalid_date = False
			except:
				day_start = day_start - 1
		return next_cycle_reset
	
	def save(self, *args, **kwargs):
		super(UserSubscription, self).save(*args, **kwargs)
		
		# Delete all other entries for this user, so we only have one active one
		if self.is_active:
			all_other_subs = UserSubscription.objects.filter(user=self.user).exclude(subscription=self.subscription)
			all_other_subs.delete()
	
	def __unicode__(self):
		return "%s (%s)" % (self.user, self.subscription)
		

# SIGNALS
subscription_signup.connect(signal_subscription_created)
subscription_cancel.connect(signal_subscription_cancel)
subscription_eot.connect(signal_subscription_expires)
payment_was_successful.connect(signal_payment_was_successful)
コード例 #8
0
            reason='cancel')
    else:
        Transaction(user=u,
                    subscription=s,
                    ipn=sender,
                    event='unexpected cancel',
                    amount=sender.mc_gross).save()
        signals.event.send(s,
                           ipn=sender,
                           subscription=s,
                           user=u,
                           event='unexpected_cancel')


subscription_cancel.connect(handle_subscription_cancel)
subscription_eot.connect(handle_subscription_cancel)


def handle_subscription_modify(sender, **kwargs):
    us = _ipn_usersubscription(sender)
    u, s = us.user, us.subscription
    print 'modify', u, s
    if us:
        # delete all user's other subscriptions
        for old_us in u.usersubscription_set.all():
            if old_us == us: continue  # don't touch current subscription
            old_us.delete()
            Transaction(user=u,
                        subscription=s,
                        ipn=sender,
                        event='remove subscription (deactivated)',