Beispiel #1
0
    def pay_for_merchant(self, Item):
        sender_batch_id = ''.join(
            random.choice(string.ascii_uppercase) for i in range(12))

        payout = Payout({
            "sender_batch_header": {
                "sender_batch_id": sender_batch_id,
                "email_subject": "You have a payment"
            },
            "items": Item
        })

        if payout.create():
            print("payout[%s] created successfully" %
                  (payout.batch_header.payout_batch_id))

            logging.basicConfig(level=logging.INFO)
            try:
                payout_batch = Payout.find(payout.batch_header.payout_batch_id)
                return payout_batch.items[0].payout_item_id

            except ResourceNotFound as error:
                print("Web Profile Not Found")

            return 1
        else:
            print(payout.error)
            return 0
Beispiel #2
0
def paypal_payment(request):
	data = {}
	logger.info("pp")
	if request.method == "POST":
		try:
			
			my_api = paypalrestsdk.Api({
				'mode': 'sandbox',
				'client_id': settings.PAYPAL_CLIENT_ID,
				'client_secret': settings.PAYPAL_CLIENT_SECRET})

			access_token = my_api.get_access_token()
			#logger.info("token %s" % access_token)
			
			batchId = request.POST.get("batchId")

			if batchId:
				resp = Payout.find(batchId, my_api)
				data["successMsg"] = resp["items"]

			else:
				emails = request.POST.get("email").split(',')
				amounts = request.POST.get("amount").split(',')
				items = []
				i = 0
				for email in emails:
					item ={
						"recipient_type": "EMAIL",
						"amount": {
							"value": amounts[i],
							"currency": "USD"
						},
						"receiver": email,
						"note": "Thank you.",
						"sender_item_id": "item_" + str(i)
					}
					items.append(item)
					i = i + 1
				
				payout = Payout({
					"sender_batch_header": {
					"sender_batch_id": "batch_2",
					"email_subject": "You have a payment"
					},
					

					"items": items
				}, api=my_api)

				if payout.create(sync_mode=False):
					data["successMsg"] = "You've successfully sent a payout, batch id: " + payout.batch_header.payout_batch_id
				else:
					logger.info(payout.error)
					data["message"] = payout.error
		except Exception as e:
			logger.info(e)
			data["message"] =	"Something went wrong."

	return render(request, "paypalTest.html", {'data': data})
 def _check_payout(self, payout):
     try:
         pay = Payout.find(payout["batch_header"]["payout_batch_id"])
         status = pay["batch_header"]["batch_status"]
         self._update_status(pay)
         if status == "DENIED":
             return False
         if status == "SUCCESS":
             self._payout_success(pay)
             return False
         if pay["batch_header"]["batch_status"] in ["PENDING", "PROCESSING"]:
             return True
         return False
     except Exception:
         return False
Beispiel #4
0
 def _check_payout(self, payout):
     try:
         pay = Payout.find(payout['batch_header']['payout_batch_id'])
         status = pay['batch_header']['batch_status']
         self._update_status(pay)
         if status == 'DENIED':
             return False
         if status == 'SUCCESS':
             self._payout_success(pay)
             return False
         if pay['batch_header']['batch_status'] in [
                 'PENDING', 'PROCESSING'
         ]:
             return True
         return False
     except Exception:
         return False
Beispiel #5
0
from paypalrestsdk import Payout, ResourceNotFound
import logging
logging.basicConfig(level=logging.INFO)

try:
    payout = Payout.find("R3LFR867ESVQY")
    print(("Got Details for Payout[%s]" % (payout.batch_header.payout_batch_id)))

except ResourceNotFound as error:
    print("Web Profile Not Found")
from paypalrestsdk import Payout, ResourceNotFound
import logging
logging.basicConfig(level=logging.INFO)

try:
    payout = Payout.find("R3LFR867ESVQY")
    print("Got Details for Payout[%s]" % (payout.batch_header.payout_batch_id))

except ResourceNotFound as error:
    print("Web Profile Not Found")