def payment_handler_task(payment_id): payment = django_pagarme_facade.find_payment(payment_id) try: slug = payment.first_item_slug() except django_pagarme_facade.PagarmePaymentItemDoesNotExist: pass # no need to handle payment with no Item else: status = payment.status() if status == django_pagarme_facade.PAID: user = payment.user if payment.payment_method == django_pagarme_facade.BOLETO: email_marketing_facade.remove_tags.delay( user.email, user.id, f'{slug}-boleto', f'{slug}-refused') else: email_marketing_facade.remove_tags.delay( user.email, user.id, f'{slug}-refused') _promote(user, slug) elif status == django_pagarme_facade.REFUSED: user = payment.user email_marketing_facade.tag_as.delay(user.email, user.id, f'{slug}-refused') elif status == django_pagarme_facade.WAITING_PAYMENT: user = payment.user email_marketing_facade.tag_as.delay(user.email, user.id, f'{slug}-boleto')
def payment_handler_task(payment_id): payment = django_pagarme_facade.find_payment(payment_id) try: slug = payment.first_item_slug() except django_pagarme_facade.PagarmePaymentItemDoesNotExist: pass # no need to handle payment with no Item else: status = payment.status() if status == django_pagarme_facade.PAID: memberkit_facade.create_new_subscription(payment, 'Criação como resposta de pagamento no Pagarme') user = payment.user if payment.payment_method == django_pagarme_facade.BOLETO: email_marketing_facade.remove_tags.delay(user.email, user.id, f'{slug}-boleto', f'{slug}-refused') else: email_marketing_facade.remove_tags.delay(user.email, user.id, f'{slug}-refused') _promote(user, slug) send_purchase_notification.delay(payment.id) elif status == django_pagarme_facade.REFUSED: user = payment.user email_marketing_facade.tag_as.delay(user.email, user.id, f'{slug}-refused') send_purchase_notification.delay(payment.id) elif status == django_pagarme_facade.WAITING_PAYMENT: user = payment.user email_marketing_facade.tag_as.delay(user.email, user.id, f'{slug}-boleto') send_purchase_notification.delay(payment.id)
def send_purchase_notification(payment_id): """ Send a potential client who filled their data but not complete the buy-in face of a refused credit card :params payment_id: id of payment """ payment = django_pagarme_facade.find_payment(payment_id) last_notification = payment.notifications.order_by('-creation').values( 'status', 'creation').first() payment_profile = django_pagarme_facade.get_user_payment_profile( payment.user_id) payment_config_items = payment.items.all() purchased_items = [{ "product_name": item.name, "quantity": '1', "price": str(item.price / 100), } for item in payment_config_items] purchase = { 'created_at': last_notification['creation'].isoformat(), 'transaction_id': payment.transaction_id, 'name': payment_profile.name, 'email': payment_profile.email, 'phone': str(payment_profile.phone), 'total_price': total_price(payment_config_items), 'line_items': purchased_items, 'payment_method': PAYMENT_METHOD_DCT[payment.payment_method], 'financial_status': STATUS_DCT[last_notification['status']], 'billet_url': payment.boleto_url, 'billet_barcode': payment.boleto_barcode, } return requests.post(settings.HOTZAPP_API_URL, json=purchase).status_code
def payment_handler_task(payment_id): payment = django_pagarme_facade.find_payment(payment_id) try: slug = payment.first_item_slug() except django_pagarme_facade.PagarmePaymentItemDoesNotExist: pass # no need to handle payment with no Item else: status = payment.status() if status == django_pagarme_facade.PAID: user = payment.user subscription_domain.create_subscription_and_activate_services( payment) if payment.payment_method == django_pagarme_facade.BOLETO: email_marketing_facade.remove_tags.delay( user.email, user.id, f'{slug}-boleto', f'{slug}-refused') else: email_marketing_facade.remove_tags.delay( user.email, user.id, f'{slug}-refused') send_purchase_notification.delay(payment.id) elif status == django_pagarme_facade.REFUSED: user = payment.user email_marketing_facade.tag_as.delay(user.email, user.id, f'{slug}-refused') send_purchase_notification.delay(payment.id) elif status == django_pagarme_facade.WAITING_PAYMENT: user = payment.user email_marketing_facade.tag_as.delay(user.email, user.id, f'{slug}-boleto') send_purchase_notification.delay(payment.id) elif status in { django_pagarme_facade.REFUNDED, django_pagarme_facade.PENDING_REFUND }: subscription_domain.inactivate_payment_subscription(payment)
def payment_handler_task(payment_id): payment = django_pagarme_facade.find_payment(payment_id) status = payment.status() slug = payment.first_item_slug() if status == django_pagarme_facade.PAID: user = payment.user _promote(user, slug) elif status == django_pagarme_facade.WAITING_PAYMENT: user = payment.user email_marketing_facade.tag_as.delay(user.email, user.id, f'{slug}-boleto')
def print_payment_id(payment_id): payment = facade.find_payment(payment_id) print(payment, payment.status())