def save_payload(self, data, payloads):
		new_payment = Payment()
		new_payment.transaction_id = data['transaction_id']
		new_payment.order_id = data['order_id']
		new_payment.gross_amount = data['gross_amount']
		new_payment.payment_type = data['payment_type']
		new_payment.transaction_time = data['transaction_time']
		new_payment.transaction_status = data['transaction_status']
		new_payment.bank = data['bank']
		new_payment.fraud_status = data['fraud_status'] if 'fraud_status' in data else None
		new_payment.masked_card = payloads['masked_card'] if 'masked_card' in payloads else None
		new_payment.saved_token_id = payloads['saved_token_id'] if 'saved_token_id' in payloads else None
		new_payment.va_number = data['va_number'] if 'va_number' in data else None

		db.session.add(new_payment)
		db.session.commit()
Exemple #2
0
    def run():
        """
        Create 4 Payments seeds
        """

        transaction_statuses = ['capture', 'authorize', 'deny']
        statuses = ['accept', 'challenge', 'deny']
        payment_types = ['bank_transfer', 'credit_card']
        banks = ['bri', 'bni', 'permata', 'maybank', 'mandiri', 'bca', 'cimb']
        range_start = 10**(7 - 1)
        range_end = (10**7) - 1
        orders = BaseModel.as_list(db.session.query(Order).all())
        for i in range(0, 4):
            order_id = choice(orders)['id']
            saved_token_id = randint(range_start, range_end)
            transaction_id = randint(range_start, range_end)
            gross_amount = randint(range_start, range_end)
            transaction_time = datetime.datetime.now()

            transaction_status = transaction_statuses[randint(0, 2)]
            masked_card = randint(range_start, range_end)
            payment_type = payment_types[randint(0, 1)]
            bank = banks[randint(0, 6)]
            fraud_status = statuses[randint(0, 2)]

            new_payment = Payment()
            new_payment.order_id = order_id
            new_payment.saved_token_id = saved_token_id
            new_payment.transaction_id = transaction_id
            new_payment.gross_amount = gross_amount
            new_payment.transaction_time = transaction_time
            new_payment.transaction_status = transaction_status
            new_payment.masked_card = masked_card
            new_payment.payment_type = payment_type
            new_payment.bank = bank
            new_payment.fraud_status = fraud_status
            db.session.add(new_payment)
            db.session.commit()
Exemple #3
0
 def confirm(self, payload, user_id, request):
     response = ResponseBuilder()
     emailservice = EmailService()
     transaction_exist = db.session.query(Payment).filter_by(
         transaction_id=payload['transaction_id']).first()
     if transaction_exist:
         return response.set_error(True).set_message(
             'this transaction have been used before').set_data(
                 None).build()
     paypal_details = self.get_paypal_detail(payload['transaction_id'])
     if paypal_details == False:
         return response.set_error(True).set_message(
             'Transaction id not found').set_data(None).build()
     paypal_details_amount = int(
         paypal_details['transactions'][0]['amount']['total'].split('.')[0])
     order_ = db.session.query(Order).filter_by(
         id=payload['order_id']).first()
     if order_ is None:
         return response.set_error(True).set_data(None).set_message(
             'Order not found').build()
     user = order_.user
     order_details = db.session.query(OrderDetails).filter_by(
         order_id=payload['order_id']).all()
     check_total = 0
     discount = 0
     for order in order_details:
         check_total += order.price * order.count
     if order_.referal_id is not None:
         discount = check_total * order_.referal.discount_amount
     if check_total - discount <= paypal_details_amount:
         payment_exist = db.session.query(Payment).filter_by(
             transaction_id=payload['transaction_id']).first()
         if payment_exist:
             return response.set_data(None).set_message(
                 'Payment had been completed!').set_error(True).build()
         payment = Payment()
         payment.order_id = payload['order_id']
         payment.transaction_id = payload['transaction_id']
         payment.gross_amount = paypal_details_amount
         payment.payment_type = 'paypal'
         payment.transaction_status = "captured"
         try:
             db.session.add(payment)
             db.session.commit()
         except SQLAlchemyError as e:
             data = e.orig.args
             return response.set_data(None).set_message(data).set_error(
                 True).build()
         items = db.session.query(OrderDetails).filter_by(
             order_id=payment.order_id).first()
         url_invoice = request.host + '/invoices/' + order_.id
         if items.ticket.type == TICKET_TYPES['exhibitor']:
             payload = {}
             payload['user_id'] = user.id
             payload['ticket_id'] = items.ticket_id
             UserTicketService().create(payload)
             self.create_booth(user)
             user_query = db.session.query(User).filter_by(id=user.id)
             user_query.update({'role_id': ROLE['booth']})
             redeem_payload = {}
             redeem_payload['ticket_id'] = items.ticket_id
             redeem_payload['codeable_id'] = user.id
             RedeemCodeService().purchase_user_redeems(redeem_payload)
             get_codes = db.session.query(RedeemCode).filter_by(
                 codeable_type='user', codeable_id=user.id).all()
             code = []
             for get_code in get_codes:
                 code.append("<li>%s</li>" % (get_code.code))
             li = ''.join(code)
             template = "<h3>You have complete the payment with order_id = %s</h3><h4>Here are the redeem codes for claiming full 3 days ticket at devsummit event as described in the package information : </h4>%s<h3>Use the above code to claim your ticket</h3><h3>Thank you for your purchase</h3>" % (
                 order_.id, li)
             template += "<h4>And here is your Invoice:</h4>"
             template += '<a href="' + url_invoice + '">Klik here to show the invoice</a>'
             email = emailservice.set_recipient(user.email).set_subject(
                 'Congratulations !! you received exhibitor code'
             ).set_sender('*****@*****.**').set_html(
                 template).build()
             mail.send(email)
         if items.ticket.type == TICKET_TYPES['hackaton']:
             payload = {}
             payload['user_id'] = user.id
             payload['ticket_id'] = items.ticket_id
             UserTicketService.create(payload)
             self.create_hackaton_team(user, items.ticket_id)
             user_query = db.session.query(User).filter_by(id=user.id)
             user_query.update({'role_id': ROLE['hackaton']})
             hacker_team = db.session.query(HackerTeam).order_by(
                 HackerTeam.created_at.desc()).first()
             redeem_payload = {}
             redeem_payload['codeable_type'] = TICKET_TYPES['hackaton']
             redeem_payload['codeable_id'] = hacker_team.id,
             redeem_payload['count'] = items.ticket.quota
             RedeemCodeService().create(redeem_payload)
             get_codes = db.session.query(RedeemCode).filter_by(
                 codeable_type='hackaton',
                 codeable_id=hacker_team.id).all()
             code = []
             for get_code in get_codes:
                 code.append("<li>%s</li>" % (get_code.code))
             li = ''.join(code)
             template = "<h3>You have complete the payment with order_id = %s</h3><h4>Here your redeem codes : </h4>%s<h3>Share the above code to your teammate, and put it into redeem code menu to let them join your team and claim their ticket</h3><h3>Thank you for your purchase</h3>" % (
                 order_.id, li)
             template += "<h4>And here is your Invoice:</h4>"
             template += '<a href="' + url_invoice + '">Klik here to show the invoice</a>'
             email = emailservice.set_recipient(user.email).set_subject(
                 'Congratulations !! you received hackaton code'
             ).set_sender('*****@*****.**').set_html(
                 template).build()
             mail.send(email)
         else:
             result = None
             for order in order_details:
                 for i in range(0, order.count):
                     payload = {}
                     payload['user_id'] = user.id
                     payload['ticket_id'] = order.ticket_id
                     result = UserTicketService().create(payload)
             if (result and (not result['error'])):
                 template = "<h3>Congratulation! you have the previlege to attend Indonesia Developer Summit</h3>"
                 template += "<h4>Here is your Invoice:</h4>"
                 template += '<a href="' + url_invoice + '">Klik here to show the invoice</a>'
                 template += "<h5>Thank you.</h5>"
                 email = emailservice.set_recipient(user.email).set_subject(
                     'Devsummit Ticket Invoice').set_sender(
                         '*****@*****.**').set_html(template).build()
                 mail.send(email)
         confirmed_order = db.session.query(Order).filter_by(
             id=payment.order_id)
         confirmed_order.update({'status': 'paid'})
         db.session.commit()
         send_notification = FCMService().send_single_notification(
             'Payment Status', 'Your payment has been confirmed', user.id,
             ROLE['admin'])
         return response.set_data(None).set_message(
             'Purchase Completed').build()
     else:
         return response.set_error(True).set_message(
             'Paypal amount did not match').build()
	def confirm(self, payload):
		response = ResponseBuilder()
		transaction_exist = db.session.query(Payment).filter_by(transaction_id=payload['transaction_id']).first()
		if transaction_exist:
			return response.set_error(True).set_message('this transaction have been used before').set_data(None).build()
		paypal_details = self.get_paypal_detail(payload['transaction_id'])
		if paypal_details == False:
			return response.set_error(True).set_message('Transaction id not found').set_data(None).build()
		paypal_details_amount = int(paypal_details['transactions'][0]['amount']['total'].split('.')[0])
		order_ = db.session.query(Order).filter_by(id=payload['order_id']).first()
		if order_ is None:
			return response.set_error(True).set_data(None).set_message('Order not found').build()
		user = order_.user
		order_details = db.session.query(OrderDetails).filter_by(order_id=payload['order_id']).all()
		check_total = 0
		for order in order_details:
			check_total += order.price * order.count	
		if check_total == paypal_details_amount:
			payment_exist = db.session.query(Payment).filter_by(transaction_id=payload['transaction_id']).first()
			if payment_exist:
				return response.set_data(None).set_message('Payment had been completed!').set_error(True).build()
			payment = Payment()
			payment.order_id = payload['order_id']
			payment.transaction_id = payload['transaction_id']
			payment.gross_amount = paypal_details_amount
			payment.payment_type = 'paypal'
			payment.transaction_status = "captured"			
			try:				
				db.session.add(payment)
				db.session.commit()
			except SQLAlchemyError as e:
				data = e.orig.args
				return response.set_data(None).set_message(data).set_error(True).build()
			items = db.session.query(OrderDetails).filter_by(order_id=payment.order_id).first()
			if items.ticket.type == TICKET_TYPES['exhibitor']:
				payload = {}
				payload['user_id'] = user.id
				payload['ticket_id'] = items.ticket_id
				UserTicketService().create(payload)
				self.create_booth(user)
				user_query = db.session.query(User).filter_by(id=user.id)
				user_query.update({
					'role_id': ROLE['booth']
				})
				redeem_payload = {}
				redeem_payload['ticket_id'] = items.ticket_id
				redeem_payload['codeable_id'] = user.id
				RedeemCodeService().purchase_user_redeems(redeem_payload)

				# user_role = db.session.query(User).filter_by(id=user.id)
				# user_role.update({
				# 	'updated_at': datetime.datetime.now(),
				# 	'role_id': 3
				# })
				# ticket_quota = order_details.ticket.quota
				# for i 
			else:				
				for order in order_details:
					for i in range(0, order.count):
						payload = {}
						payload['user_id'] = user.id
						payload['ticket_id'] = order.ticket_id
						UserTicketService().create(payload)
			confirmed_order = db.session.query(Order).filter_by(id=payment.order_id)
			confirmed_order.update({
				'status': 'paid'
			})
			db.session.commit()
			return response.set_data(None).set_message('Purchase Completed').build()
		else:
			return response.set_error(True).set_message('Paypal amount did not match').build()