mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Storing iOS payment transaction identifier so as to not upgrade a user multiple times.
This commit is contained in:
parent
055e8f0352
commit
8fe07dc701
3 changed files with 31 additions and 16 deletions
|
@ -415,13 +415,24 @@ class Profile(models.Model):
|
||||||
|
|
||||||
return ipn[0].payer_email
|
return ipn[0].payer_email
|
||||||
|
|
||||||
def activate_ios_premium(self, amount):
|
def activate_ios_premium(self, product_identifier, transaction_identifier, amount=36):
|
||||||
|
payments = PaymentHistory.objects.filter(user=self.user,
|
||||||
|
payment_identifier=transaction_identifier)
|
||||||
|
if len(payments):
|
||||||
|
# Already paid
|
||||||
|
return False
|
||||||
|
|
||||||
PaymentHistory.objects.create(user=self.user,
|
PaymentHistory.objects.create(user=self.user,
|
||||||
payment_date=datetime.datetime.now(),
|
payment_date=datetime.datetime.now(),
|
||||||
payment_amount=amount,
|
payment_amount=amount,
|
||||||
payment_provider='ios-subscription')
|
payment_provider='ios-subscription',
|
||||||
self.activate_premium()
|
payment_identifier=transaction_identifier)
|
||||||
logging.user(self.user, "~FG~BBNew iOS premium subscription: $%s~FW" % amount)
|
|
||||||
|
if not self.is_premium:
|
||||||
|
self.activate_premium()
|
||||||
|
|
||||||
|
logging.user(self.user, "~FG~BBNew iOS premium subscription: $%s~FW" % product_identifier)
|
||||||
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def clear_dead_spammers(self, days=30, confirm=False):
|
def clear_dead_spammers(self, days=30, confirm=False):
|
||||||
|
@ -1124,6 +1135,7 @@ class PaymentHistory(models.Model):
|
||||||
payment_date = models.DateTimeField()
|
payment_date = models.DateTimeField()
|
||||||
payment_amount = models.IntegerField()
|
payment_amount = models.IntegerField()
|
||||||
payment_provider = models.CharField(max_length=20)
|
payment_provider = models.CharField(max_length=20)
|
||||||
|
payment_identifier = models.CharField(max_length=100)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return "[%s] $%s/%s" % (self.payment_date.strftime("%Y-%m-%d"), self.payment_amount,
|
return "[%s] $%s/%s" % (self.payment_date.strftime("%Y-%m-%d"), self.payment_amount,
|
||||||
|
|
|
@ -313,16 +313,17 @@ def profile_is_premium(request):
|
||||||
@ajax_login_required
|
@ajax_login_required
|
||||||
@json.json_view
|
@json.json_view
|
||||||
def save_ios_receipt(request):
|
def save_ios_receipt(request):
|
||||||
request.user.profile.activate_ios_premium(36)
|
receipt = request.REQUEST.get('receipt')
|
||||||
|
product_identifier = request.POST.get('product_identifier')
|
||||||
|
transaction_identifier = request.POST.get('transaction_identifier')
|
||||||
|
|
||||||
subject = "iOS Premium: %s" % (request.user.profile)
|
paid = request.user.profile.activate_ios_premium(product_identifier, transaction_identifier)
|
||||||
message = """User: %s (%s) -- Email: %s, receipt: %s""" % (request.user.username, request.user.pk, request.user.email, request.REQUEST.get('receipt', None))
|
if paid:
|
||||||
mail_admins(subject, message, fail_silently=True)
|
subject = "iOS Premium: %s (%s)" % (request.user.profile, product_identifier)
|
||||||
|
message = """User: %s (%s) -- Email: %s, product: %s, txn: %s, receipt: %s""" % (request.user.username, request.user.pk, request.user.email, product_identifier, transaction_identifier, receipt)
|
||||||
|
mail_admins(subject, message, fail_silently=True)
|
||||||
|
|
||||||
return {
|
return request.user.profile
|
||||||
'is_premium': request.user.profile.is_premium,
|
|
||||||
'premium_expire': request.user.profile.premium_expire,
|
|
||||||
}
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def stripe_form(request):
|
def stripe_form(request):
|
||||||
|
|
|
@ -170,7 +170,7 @@
|
||||||
//NSString *productID = transaction.payment.productIdentifier;
|
//NSString *productID = transaction.payment.productIdentifier;
|
||||||
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
|
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
|
||||||
|
|
||||||
[self finishTransaction];
|
[self finishTransaction:transaction];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@
|
||||||
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
|
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
|
||||||
NSLog(@"Transaction state -> Purchased");
|
NSLog(@"Transaction state -> Purchased");
|
||||||
|
|
||||||
[self finishTransaction];
|
[self finishTransaction:transaction];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SKPaymentTransactionStateRestored:
|
case SKPaymentTransactionStateRestored:
|
||||||
|
@ -197,7 +197,7 @@
|
||||||
//add the same code as you did from SKPaymentTransactionStatePurchased here
|
//add the same code as you did from SKPaymentTransactionStatePurchased here
|
||||||
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
|
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
|
||||||
|
|
||||||
[self finishTransaction];
|
[self finishTransaction:transaction];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SKPaymentTransactionStateFailed:
|
case SKPaymentTransactionStateFailed:
|
||||||
|
@ -215,7 +215,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)finishTransaction {
|
- (void)finishTransaction:(SKPaymentTransaction *)transaction {
|
||||||
productsTable.hidden = YES;
|
productsTable.hidden = YES;
|
||||||
spinner.hidden = NO;
|
spinner.hidden = NO;
|
||||||
|
|
||||||
|
@ -231,6 +231,8 @@
|
||||||
appDelegate.url];
|
appDelegate.url];
|
||||||
NSDictionary *params = @{
|
NSDictionary *params = @{
|
||||||
@"receipt": [receipt base64EncodedStringWithOptions:0],
|
@"receipt": [receipt base64EncodedStringWithOptions:0],
|
||||||
|
@"transaction_identifier": transaction.transactionIdentifier,
|
||||||
|
@"product_identifier": transaction.payment.productIdentifier,
|
||||||
};
|
};
|
||||||
|
|
||||||
[appDelegate.networkManager POST:urlString parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
[appDelegate.networkManager POST:urlString parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue