def cancel_premium_paypal(self): transactions = PayPalIPN.objects.filter(custom=self.user.username, txn_type='subscr_signup') if not transactions: return paypal_opts = { 'API_ENVIRONMENT': 'PRODUCTION', 'API_USERNAME': settings.PAYPAL_API_USERNAME, 'API_PASSWORD': settings.PAYPAL_API_PASSWORD, 'API_SIGNATURE': settings.PAYPAL_API_SIGNATURE, } paypal = PayPalInterface(**paypal_opts) transaction = transactions[0] profileid = transaction.subscr_id try: paypal.manage_recurring_payments_profile_status( profileid=profileid, action='Cancel') except PayPalAPIResponseError: logging.user(self.user, "~FRUser ~SBalready~SN canceled Paypal subscription") else: logging.user(self.user, "~FRCanceling Paypal subscription") return True
def refund_premium(self): refunded = False if self.stripe_id: stripe.api_key = settings.STRIPE_SECRET stripe_customer = stripe.Customer.retrieve(self.stripe_id) stripe_payments = stripe.Charge.all(customer=stripe_customer.id).data stripe_payments[0].refund() refunded = stripe_payments[0].amount/100 logging.user(self.user, "~FRRefunding stripe payment: $%s" % refunded) self.cancel_premium() else: paypal_opts = { 'API_ENVIRONMENT': 'PRODUCTION', 'API_USERNAME': settings.PAYPAL_API_USERNAME, 'API_PASSWORD': settings.PAYPAL_API_PASSWORD, 'API_SIGNATURE': settings.PAYPAL_API_SIGNATURE, } paypal = PayPalInterface(**paypal_opts) transaction = PayPalIPN.objects.filter(custom=self.user.username, txn_type='subscr_payment')[0] refund = paypal.refund_transaction(transaction.txn_id) refunded = int(float(refund['raw']['TOTALREFUNDEDAMOUNT'][0])) logging.user(self.user, "~FRRefunding paypal payment: $%s" % refunded) self.cancel_premium() return refunded
def refund_premium(self, partial=False): refunded = False if self.stripe_id: stripe.api_key = settings.STRIPE_SECRET stripe_customer = stripe.Customer.retrieve(self.stripe_id) stripe_payments = stripe.Charge.all(customer=stripe_customer.id).data if partial: stripe_payments[0].refund(amount=1200) refunded = 12 else: stripe_payments[0].refund() self.cancel_premium() refunded = stripe_payments[0].amount/100 logging.user(self.user, "~FRRefunding stripe payment: $%s" % refunded) else: paypal_opts = { 'API_ENVIRONMENT': 'PRODUCTION', 'API_USERNAME': settings.PAYPAL_API_USERNAME, 'API_PASSWORD': settings.PAYPAL_API_PASSWORD, 'API_SIGNATURE': settings.PAYPAL_API_SIGNATURE, } paypal = PayPalInterface(**paypal_opts) transaction = PayPalIPN.objects.filter(custom=self.user.username, txn_type='subscr_payment')[0] refund = paypal.refund_transaction(transaction.txn_id) try: refunded = int(float(refund.raw['TOTALREFUNDEDAMOUNT'][0])) except KeyError: refunded = int(transaction.payment_gross) logging.user(self.user, "~FRRefunding paypal payment: $%s" % refunded) self.cancel_premium() return refunded
def refund_premium(self, partial=False): refunded = False if self.stripe_id: stripe.api_key = settings.STRIPE_SECRET stripe_customer = stripe.Customer.retrieve(self.stripe_id) stripe_payments = stripe.Charge.all(customer=stripe_customer.id).data if partial: stripe_payments[0].refund(amount=1200) refunded = 12 else: stripe_payments[0].refund() self.cancel_premium() refunded = stripe_payments[0].amount / 100 logging.user(self.user, "~FRRefunding stripe payment: $%s" % refunded) else: paypal_opts = { "API_ENVIRONMENT": "PRODUCTION", "API_USERNAME": settings.PAYPAL_API_USERNAME, "API_PASSWORD": settings.PAYPAL_API_PASSWORD, "API_SIGNATURE": settings.PAYPAL_API_SIGNATURE, } paypal = PayPalInterface(**paypal_opts) transaction = PayPalIPN.objects.filter(custom=self.user.username, txn_type="subscr_payment")[0] refund = paypal.refund_transaction(transaction.txn_id) try: refunded = int(float(refund.raw["TOTALREFUNDEDAMOUNT"][0])) except KeyError: refunded = int(transaction.payment_gross) logging.user(self.user, "~FRRefunding paypal payment: $%s" % refunded) self.cancel_premium() return refunded
def cancel_premium_paypal(self): transactions = PayPalIPN.objects.filter( custom=self.user.username, txn_type='subscr_signup') if not transactions: return paypal_opts = { 'API_ENVIRONMENT': 'PRODUCTION', 'API_USERNAME': settings.PAYPAL_API_USERNAME, 'API_PASSWORD': settings.PAYPAL_API_PASSWORD, 'API_SIGNATURE': settings.PAYPAL_API_SIGNATURE, } paypal = PayPalInterface(**paypal_opts) transaction = transactions[0] profileid = transaction.subscr_id try: paypal.manage_recurring_payments_profile_status( profileid=profileid, action='Cancel') except PayPalAPIResponseError: logging.user(self.user, "~FRUser ~SBalready~SN canceled Paypal subscription") else: logging.user(self.user, "~FRCanceling Paypal subscription") return True
def refund_premium(self, partial=False): refunded = False if self.stripe_id: stripe.api_key = settings.STRIPE_SECRET stripe_customer = stripe.Customer.retrieve(self.stripe_id) stripe_payments = stripe.Charge.all(customer=stripe_customer.id).data if partial: stripe_payments[0].refund(amount=1200) refunded = 12 else: stripe_payments[0].refund() self.cancel_premium() refunded = stripe_payments[0].amount/100 logging.user(self.user, "~FRRefunding stripe payment: $%s" % refunded) else: self.cancel_premium() paypal_opts = { 'API_ENVIRONMENT': 'PRODUCTION', 'API_USERNAME': settings.PAYPAL_API_USERNAME, 'API_PASSWORD': settings.PAYPAL_API_PASSWORD, 'API_SIGNATURE': settings.PAYPAL_API_SIGNATURE, 'API_CA_CERTS': False, } paypal = PayPalInterface(**paypal_opts) transactions = PayPalIPN.objects.filter(custom=self.user.username, txn_type='subscr_payment' ).order_by('-payment_date') if not transactions: transactions = PayPalIPN.objects.filter(payer_email=self.user.email, txn_type='subscr_payment' ).order_by('-payment_date') if transactions: transaction = transactions[0] refund = paypal.refund_transaction(transaction.txn_id) try: refunded = int(float(refund.raw['TOTALREFUNDEDAMOUNT'][0])) except KeyError: refunded = int(transaction.payment_gross) logging.user(self.user, "~FRRefunding paypal payment: $%s" % refunded) else: logging.user(self.user, "~FRCouldn't refund paypal payment: not found by username or email") refunded = 0 return refunded
def cancel_premium_paypal(self): transactions = PayPalIPN.objects.filter(custom=self.user.username, txn_type="subscr_signup") if not transactions: return paypal_opts = { "API_ENVIRONMENT": "PRODUCTION", "API_USERNAME": settings.PAYPAL_API_USERNAME, "API_PASSWORD": settings.PAYPAL_API_PASSWORD, "API_SIGNATURE": settings.PAYPAL_API_SIGNATURE, } paypal = PayPalInterface(**paypal_opts) transaction = transactions[0] profileid = transaction.subscr_id paypal.manage_recurring_payments_profile_status(profileid=profileid, action="Cancel") logging.user(self.user, "~FRCanceling Paypal subscription") return True