mirror of
https://github.com/viq/NewsBlur.git
synced 2025-08-05 16:49:45 +00:00
Turning off shipping, adding user_id to subscription, and upgrading user. Now need renewals and cancellations.
This commit is contained in:
parent
88d07b143c
commit
c18c16a0c3
4 changed files with 38 additions and 6 deletions
|
@ -88,6 +88,19 @@ class Profile(models.Model):
|
|||
price = "price_0KK5twwdsmP8XBlasifbX56Z"
|
||||
return price
|
||||
|
||||
@classmethod
|
||||
def paypal_plan_id_to_plan(cls, plan_id):
|
||||
if settings.DEBUG:
|
||||
if plan_id == "P-4RV31836YD8080909MHZROJY":
|
||||
return "premium"
|
||||
elif plan_id == "P-2EG40290653242115MHZROQQ":
|
||||
return "archive"
|
||||
else:
|
||||
if plan_id == "P-48R22630SD810553FMHZONIY":
|
||||
return "premium"
|
||||
elif plan_id == "P-5JM46230U31841226MHZOMZY":
|
||||
return "archive"
|
||||
|
||||
@property
|
||||
def unread_cutoff(self, force_premium=False, force_archive=False):
|
||||
if self.is_archive or force_archive:
|
||||
|
|
|
@ -15,7 +15,7 @@ urlpatterns = [
|
|||
url(r'^switch_subscription/?', views.switch_subscription, name='switch-subscription'),
|
||||
url(r'^is_premium/?', views.profile_is_premium, name='profile-is-premium'),
|
||||
url(r'^paypal_ipn/?', include('paypal.standard.ipn.urls'), name='paypal-ipn'),
|
||||
url(r'^paypal_webhooks/?', include('paypal.standard.ipn.urls'), name='paypal-webhooks'),
|
||||
url(r'^paypal_webhooks/?', views.paypal_webhooks, name='paypal-webhooks'),
|
||||
url(r'^stripe_form/?', views.stripe_form, name='stripe-form'),
|
||||
url(r'^stripe_checkout/?', views.stripe_checkout, name='stripe-checkout'),
|
||||
url(r'^activities/?', views.load_activities, name='profile-activities'),
|
||||
|
|
|
@ -259,7 +259,23 @@ def set_collapsed_folders(request):
|
|||
response = dict(code=code)
|
||||
return response
|
||||
|
||||
@ajax_login_required
|
||||
def paypal_webhooks(request):
|
||||
data = json.decode(request.body)
|
||||
logging.user(request, f"{data}")
|
||||
|
||||
if data['event_type'] == "BILLING.SUBSCRIPTION.CREATED":
|
||||
user = User.objects.get(pk=int(data['resource']['custom_id']))
|
||||
plan = Profile.paypal_plan_id_to_plan(data['resource']['plan_id'])
|
||||
if plan == "premium":
|
||||
user.profile.activate_premium()
|
||||
elif plan == "archive":
|
||||
user.profile.activate_archive()
|
||||
user.profile.cancel_premium_stripe()
|
||||
elif data['event_type'] == "":
|
||||
pass
|
||||
|
||||
return HttpResponse("OK")
|
||||
|
||||
def paypal_form(request):
|
||||
domain = Site.objects.get_current().domain
|
||||
|
||||
|
|
|
@ -303,20 +303,23 @@ _.extend(NEWSBLUR.ReaderFeedchooser.prototype, {
|
|||
shape: 'rect',
|
||||
color: 'silver',
|
||||
layout: 'horizontal',
|
||||
label: 'paypal',
|
||||
|
||||
label: 'paypal',
|
||||
},
|
||||
|
||||
createSubscription: function (data, actions) {
|
||||
return actions.subscription.create({
|
||||
'plan_id': plan_id
|
||||
'plan_id': plan_id,
|
||||
'application_context': {
|
||||
shipping_preference: 'NO_SHIPPING'
|
||||
},
|
||||
'custom_id': NEWSBLUR.Globals.user_id
|
||||
});
|
||||
},
|
||||
|
||||
onApprove: function (data, actions) {
|
||||
// Full available details
|
||||
console.log('Paypal approve result', data.subscriptionID, JSON.stringify(data, null, 2));
|
||||
// actions.redirect(NEWSBLUR.URLs.paypal_return);
|
||||
actions.redirect(NEWSBLUR.URLs.paypal_return);
|
||||
},
|
||||
|
||||
onError: function (err) {
|
||||
|
|
Loading…
Add table
Reference in a new issue