def PostContext(self):
     tResponse = {}
     tResponse['tResponseText'] = ""
     tPaypal = VipCancelPaypalAjax()
     tResultDictionary = {}
     tPaypalPayload = {}        
     tPayload = {}
     
     pSubscriptionKey = str(self.request.get('key'))
     tSubscription = VipSubscription()
     try:
         tSubscription = VipSubscription.get(pSubscriptionKey)
     except:
         tResponse['tResponseText'] = "Not Found"
         return tResponse
     #logging.debug("Subscription found with owner: " + tSubscription.subscriptionOwner)
     
     if (tSubscription):            
                 
         tPaypalPayload['METHOD'] = "ManageRecurringPaymentsProfileStatus"
         tPaypalPayload['PROFILEID'] = str(tSubscription.subscriptionId) 
         tPaypalPayload['ACTION'] = 'Cancel'
         
         tPayloadEncoded = tPaypal.GeneratePayload(tPaypalPayload)                
         
         request_cookies = mechanize.CookieJar()
         request_opener = mechanize.build_opener(mechanize.HTTPCookieProcessor(request_cookies))
         request_opener.addheaders = [('Content-Type', 'application/x-www-form-urlencoded')]
         mechanize.install_opener(request_opener)
             
         tResponse = mechanize.urlopen(url = tUrl, timeout = 25.0, data = tPayloadEncoded)
         tResult = str(urllib.unquote(tResponse.read()))
         
         #logging.debug("Mechanize Package")
         #logging.debug("Url: " + tUrl)
         #logging.debug("Data: " + str(tPaypalPayload))
         #logging.debug("Response: " + tResult)
         
         tResultSplit = tResult.split('&')
         
         for tPair in tResultSplit:
             tSplitPair = tPair.split("=")
             tResultDictionary[tSplitPair[0]] = tSplitPair[1]
         
         tResponse['tResponseText'] = "Cancelled"
         
         tSubscription.subscriptionIsActive = False
         tSubscription.subscriptionEnd = datetime.datetime.now()        
         tSubscription.subscriptionNeedsUpgrade = False
         tSubscription.subscriptionNeedsCancel = False
         tSubscription.put()    
         
         tSubscriber = VipSubscriber()
         tSubscriber.subscriberActiveSubscription = ""
         tSubscriber.subscriberHasActiveSubscription = False
         tSubscriber.put()
         
     return tResponse
Esempio n. 2
0
    def ProcessSubscription(self, pArgumentDic):
        tVipSubscriber = VipSubscriber()
        tVipSub = VipSubscription()
        tVipPayment = VipPayment()
        tLogList = []

        tOwnerEmail = pArgumentDic['payer_email']
        tOwnerId = pArgumentDic['payer_id']
        tVipSubscriber = VipSubscriber.GetSubscriberByIdAndEmail(
            tOwnerId, tOwnerEmail)
        tVipSubs = VipSubscription.GetActiveSubscriptionsByOwner(tOwnerId)

        if (tVipSubs != None and len(tVipSubs) > 0):
            tVipSub = tVipSubs[0]
            tVipSub.subscriptionIsActive = True
            tLogList = tVipSub.subscriptionLog
            tLogList.append("Paid: " + str(datetime.datetime.now()) +
                            " with transaction id " + pArgumentDic['txn_id'])
            tVipSub.subscriptionLog = tLogList
        else:
            tVipSub.subscriptionAutoState = "Tier0"
            tVipSub.subscriptionId = pArgumentDic['subscr_id']
            tLogList = tVipSub.subscriptionLog
            tLogList.append("Started: " + str(datetime.datetime.now()) +
                            " with transaction id " + pArgumentDic['txn_id'])
            tVipSub.subscriptionLog = tLogList
            tVipSub.subscriptionNeedsUpgrade = True
            tVipSub.subscriptionOwner = tOwnerId

        tVipSub.subscriptionIsActive = True
        tSubKey = str(tVipSub.put())

        tVipSubscriber.subscriberHasActiveSubscription = True
        tVipSubscriber.subscriberActiveSubscription = tSubKey
        tSubList = []
        tSubList = tVipSubscriber.subscriberSubscriptions
        tSubList.append(tSubKey)
        tVipSubscriber.put()

        if ('payment_gross' in pArgumentDic.keys()):
            tVipPayment.paymentAmount = pArgumentDic['payment_gross']

        tVipPayment.paymentEmail = tOwnerEmail
        tVipPayment.paymentPaypalId = tOwnerId
        tVipPayment.put()
Esempio n. 3
0
    def ProcessSubscription(self, pArgumentDic):
        tVipSubscriber = VipSubscriber()
        tVipSub = VipSubscription()
        tVipPayment = VipPayment()
        tLogList = []

        tOwnerEmail = pArgumentDic["payer_email"]
        tOwnerId = pArgumentDic["payer_id"]
        tVipSubscriber = VipSubscriber.GetSubscriberByIdAndEmail(tOwnerId, tOwnerEmail)
        tVipSubs = VipSubscription.GetActiveSubscriptionsByOwner(tOwnerId)

        if tVipSubs != None and len(tVipSubs) > 0:
            tVipSub = tVipSubs[0]
            tVipSub.subscriptionIsActive = True
            tLogList = tVipSub.subscriptionLog
            tLogList.append("Paid: " + str(datetime.datetime.now()) + " with transaction id " + pArgumentDic["txn_id"])
            tVipSub.subscriptionLog = tLogList
        else:
            tVipSub.subscriptionAutoState = "Tier0"
            tVipSub.subscriptionId = pArgumentDic["subscr_id"]
            tLogList = tVipSub.subscriptionLog
            tLogList.append(
                "Started: " + str(datetime.datetime.now()) + " with transaction id " + pArgumentDic["txn_id"]
            )
            tVipSub.subscriptionLog = tLogList
            tVipSub.subscriptionNeedsUpgrade = True
            tVipSub.subscriptionOwner = tOwnerId

        tVipSub.subscriptionIsActive = True
        tSubKey = str(tVipSub.put())

        tVipSubscriber.subscriberHasActiveSubscription = True
        tVipSubscriber.subscriberActiveSubscription = tSubKey
        tSubList = []
        tSubList = tVipSubscriber.subscriberSubscriptions
        tSubList.append(tSubKey)
        tVipSubscriber.put()

        if "payment_gross" in pArgumentDic.keys():
            tVipPayment.paymentAmount = pArgumentDic["payment_gross"]

        tVipPayment.paymentEmail = tOwnerEmail
        tVipPayment.paymentPaypalId = tOwnerId
        tVipPayment.put()
Esempio n. 4
0
    def ProcessSubscriptionCancellation(self, pArgumentDic):
        tVipSubscriber = VipSubscriber()
        tVipSub = VipSubscription()
        tVipPayment = VipPayment()
        tLogList = []

        tOwnerEmail = pArgumentDic['payer_email']
        tOwnerId = pArgumentDic['payer_id']

        tVipSubList = VipSubscription.GetActiveSubscriptionsByOwner(tOwnerId)

        if (tVipSubList != None):
            if (len(tVipSubList) > 0):
                tVipSub = tVipSubList[0]
                tVipSub.subscriptionIsActive = False
                tVipSub.subscriptionEnd = datetime.datetime.now()
                tVipSub.subscriptionNeedsCancel = True
                tVipSub.put()

        tVipSubscriber.subscriberHasActiveSubscription = False
        tVipSubscriber.subscriberActiveSubscription = ""
        tVipSubscriber.put()
Esempio n. 5
0
    def ProcessSubscriptionCancellation(self, pArgumentDic):
        tVipSubscriber = VipSubscriber()
        tVipSub = VipSubscription()
        tVipPayment = VipPayment()
        tLogList = []

        tOwnerEmail = pArgumentDic["payer_email"]
        tOwnerId = pArgumentDic["payer_id"]

        tVipSubList = VipSubscription.GetActiveSubscriptionsByOwner(tOwnerId)

        if tVipSubList != None:
            if len(tVipSubList) > 0:
                tVipSub = tVipSubList[0]
                tVipSub.subscriptionIsActive = False
                tVipSub.subscriptionEnd = datetime.datetime.now()
                tVipSub.subscriptionNeedsCancel = True
                tVipSub.put()

        tVipSubscriber.subscriberHasActiveSubscription = False
        tVipSubscriber.subscriberActiveSubscription = ""
        tVipSubscriber.put()
    def PostContext(self):
        tResponse = {}
        tResponse['tResponseText'] = ""
        tPaypal = VipCancelPaypalAjax()
        tResultDictionary = {}
        tPaypalPayload = {}
        tPayload = {}

        pSubscriptionKey = str(self.request.get('key'))
        tSubscription = VipSubscription()
        try:
            tSubscription = VipSubscription.get(pSubscriptionKey)
        except:
            tResponse['tResponseText'] = "Not Found"
            return tResponse
        #logging.debug("Subscription found with owner: " + tSubscription.subscriptionOwner)

        if (tSubscription):

            tPaypalPayload['METHOD'] = "ManageRecurringPaymentsProfileStatus"
            tPaypalPayload['PROFILEID'] = str(tSubscription.subscriptionId)
            tPaypalPayload['ACTION'] = 'Cancel'

            tPayloadEncoded = tPaypal.GeneratePayload(tPaypalPayload)

            request_cookies = mechanize.CookieJar()
            request_opener = mechanize.build_opener(
                mechanize.HTTPCookieProcessor(request_cookies))
            request_opener.addheaders = [('Content-Type',
                                          'application/x-www-form-urlencoded')]
            mechanize.install_opener(request_opener)

            tResponse = mechanize.urlopen(url=tUrl,
                                          timeout=25.0,
                                          data=tPayloadEncoded)
            tResult = str(urllib.unquote(tResponse.read()))

            #logging.debug("Mechanize Package")
            #logging.debug("Url: " + tUrl)
            #logging.debug("Data: " + str(tPaypalPayload))
            #logging.debug("Response: " + tResult)

            tResultSplit = tResult.split('&')

            for tPair in tResultSplit:
                tSplitPair = tPair.split("=")
                tResultDictionary[tSplitPair[0]] = tSplitPair[1]

            tResponse['tResponseText'] = "Cancelled"

            tSubscription.subscriptionIsActive = False
            tSubscription.subscriptionEnd = datetime.datetime.now()
            tSubscription.subscriptionNeedsUpgrade = False
            tSubscription.subscriptionNeedsCancel = False
            tSubscription.put()

            tSubscriber = VipSubscriber()
            tSubscriber.subscriberActiveSubscription = ""
            tSubscriber.subscriberHasActiveSubscription = False
            tSubscriber.put()

        return tResponse