How can I send variables to paypal api and get them back with python SDK?












1















I am making a marketplace-type app with sellers and buyers and am trying to integrate PayPal API as a means to pay between users.



I need to be able to send the seller's username(on my website) as a parameter to PayPal API and get it back after a successful payment so I can notify the seller he has been paid. How can this be accomplished?



from paypalrestsdk import Payment
from django.http import HttpResponseRedirect
def payment_page(request):

if request.method == 'POST':
approval_url = 'http://127.0.0.1:8000/'
paypalrestsdk.configure({
"mode": "sandbox", # sandbox or live
"client_id": "client_id",
"client_secret": "client_secret"})

payment = paypalrestsdk.Payment({
"intent": "sale",
"payer": {
"payment_method": "paypal"},
"redirect_urls": {
"return_url": "http://localhost:8000/success",
"cancel_url": "http://localhost:8000/fail"},
"transactions": [{
"item_list": {
"items": [{
"name": "item",
"sku": "item",
"price": "5.00",
"currency": "USD",
"quantity": 1}]},
"amount": {
"total": "5.00",
"currency": "USD"},
"description": "This is the payment transaction description."}]})

if payment.create():
print("Payment created successfully")

for link in payment.links:
if link.rel == "approval_url":
# Convert to str to avoid Google App Engine Unicode issue
# https://github.com/paypal/rest-api-sdk-python/pull/58
approval_url = str(link.href)
print("Redirect for approval: %s" % (approval_url))
return HttpResponseRedirect(approval_url)
else:
print(payment.error)
else:
print('loading page')
return render(request, 'app/payment.html')


def success(request):
//Here I also want to capture seller username and buyer username

payment_id = request.GET.get('paymentId')
payer_id = request.GET.get('PayerID')
# Payment ID obtained when creating the payment (following redirect)
payment = Payment.find(payment_id)

# Execute payment with the payer ID from the create payment call (following redirect)
if payment.execute({"payer_id": payer_id}):
print("Payment[%s] execute successfully" % (payment.id))
else:
print(payment.error)

return render(request, 'app/success.html')


my payment.html payment template



<html>
<head>

</head>


<body>
<h3>Seller username:foo1 Buyer username:foo2</h3>

<form action='{% url "app:payment_page" %}' method='post'>
{% csrf_token %}
<input type='submit' value='pay'>

</form>
</body>




</html>









share|improve this question



























    1















    I am making a marketplace-type app with sellers and buyers and am trying to integrate PayPal API as a means to pay between users.



    I need to be able to send the seller's username(on my website) as a parameter to PayPal API and get it back after a successful payment so I can notify the seller he has been paid. How can this be accomplished?



    from paypalrestsdk import Payment
    from django.http import HttpResponseRedirect
    def payment_page(request):

    if request.method == 'POST':
    approval_url = 'http://127.0.0.1:8000/'
    paypalrestsdk.configure({
    "mode": "sandbox", # sandbox or live
    "client_id": "client_id",
    "client_secret": "client_secret"})

    payment = paypalrestsdk.Payment({
    "intent": "sale",
    "payer": {
    "payment_method": "paypal"},
    "redirect_urls": {
    "return_url": "http://localhost:8000/success",
    "cancel_url": "http://localhost:8000/fail"},
    "transactions": [{
    "item_list": {
    "items": [{
    "name": "item",
    "sku": "item",
    "price": "5.00",
    "currency": "USD",
    "quantity": 1}]},
    "amount": {
    "total": "5.00",
    "currency": "USD"},
    "description": "This is the payment transaction description."}]})

    if payment.create():
    print("Payment created successfully")

    for link in payment.links:
    if link.rel == "approval_url":
    # Convert to str to avoid Google App Engine Unicode issue
    # https://github.com/paypal/rest-api-sdk-python/pull/58
    approval_url = str(link.href)
    print("Redirect for approval: %s" % (approval_url))
    return HttpResponseRedirect(approval_url)
    else:
    print(payment.error)
    else:
    print('loading page')
    return render(request, 'app/payment.html')


    def success(request):
    //Here I also want to capture seller username and buyer username

    payment_id = request.GET.get('paymentId')
    payer_id = request.GET.get('PayerID')
    # Payment ID obtained when creating the payment (following redirect)
    payment = Payment.find(payment_id)

    # Execute payment with the payer ID from the create payment call (following redirect)
    if payment.execute({"payer_id": payer_id}):
    print("Payment[%s] execute successfully" % (payment.id))
    else:
    print(payment.error)

    return render(request, 'app/success.html')


    my payment.html payment template



    <html>
    <head>

    </head>


    <body>
    <h3>Seller username:foo1 Buyer username:foo2</h3>

    <form action='{% url "app:payment_page" %}' method='post'>
    {% csrf_token %}
    <input type='submit' value='pay'>

    </form>
    </body>




    </html>









    share|improve this question

























      1












      1








      1








      I am making a marketplace-type app with sellers and buyers and am trying to integrate PayPal API as a means to pay between users.



      I need to be able to send the seller's username(on my website) as a parameter to PayPal API and get it back after a successful payment so I can notify the seller he has been paid. How can this be accomplished?



      from paypalrestsdk import Payment
      from django.http import HttpResponseRedirect
      def payment_page(request):

      if request.method == 'POST':
      approval_url = 'http://127.0.0.1:8000/'
      paypalrestsdk.configure({
      "mode": "sandbox", # sandbox or live
      "client_id": "client_id",
      "client_secret": "client_secret"})

      payment = paypalrestsdk.Payment({
      "intent": "sale",
      "payer": {
      "payment_method": "paypal"},
      "redirect_urls": {
      "return_url": "http://localhost:8000/success",
      "cancel_url": "http://localhost:8000/fail"},
      "transactions": [{
      "item_list": {
      "items": [{
      "name": "item",
      "sku": "item",
      "price": "5.00",
      "currency": "USD",
      "quantity": 1}]},
      "amount": {
      "total": "5.00",
      "currency": "USD"},
      "description": "This is the payment transaction description."}]})

      if payment.create():
      print("Payment created successfully")

      for link in payment.links:
      if link.rel == "approval_url":
      # Convert to str to avoid Google App Engine Unicode issue
      # https://github.com/paypal/rest-api-sdk-python/pull/58
      approval_url = str(link.href)
      print("Redirect for approval: %s" % (approval_url))
      return HttpResponseRedirect(approval_url)
      else:
      print(payment.error)
      else:
      print('loading page')
      return render(request, 'app/payment.html')


      def success(request):
      //Here I also want to capture seller username and buyer username

      payment_id = request.GET.get('paymentId')
      payer_id = request.GET.get('PayerID')
      # Payment ID obtained when creating the payment (following redirect)
      payment = Payment.find(payment_id)

      # Execute payment with the payer ID from the create payment call (following redirect)
      if payment.execute({"payer_id": payer_id}):
      print("Payment[%s] execute successfully" % (payment.id))
      else:
      print(payment.error)

      return render(request, 'app/success.html')


      my payment.html payment template



      <html>
      <head>

      </head>


      <body>
      <h3>Seller username:foo1 Buyer username:foo2</h3>

      <form action='{% url "app:payment_page" %}' method='post'>
      {% csrf_token %}
      <input type='submit' value='pay'>

      </form>
      </body>




      </html>









      share|improve this question














      I am making a marketplace-type app with sellers and buyers and am trying to integrate PayPal API as a means to pay between users.



      I need to be able to send the seller's username(on my website) as a parameter to PayPal API and get it back after a successful payment so I can notify the seller he has been paid. How can this be accomplished?



      from paypalrestsdk import Payment
      from django.http import HttpResponseRedirect
      def payment_page(request):

      if request.method == 'POST':
      approval_url = 'http://127.0.0.1:8000/'
      paypalrestsdk.configure({
      "mode": "sandbox", # sandbox or live
      "client_id": "client_id",
      "client_secret": "client_secret"})

      payment = paypalrestsdk.Payment({
      "intent": "sale",
      "payer": {
      "payment_method": "paypal"},
      "redirect_urls": {
      "return_url": "http://localhost:8000/success",
      "cancel_url": "http://localhost:8000/fail"},
      "transactions": [{
      "item_list": {
      "items": [{
      "name": "item",
      "sku": "item",
      "price": "5.00",
      "currency": "USD",
      "quantity": 1}]},
      "amount": {
      "total": "5.00",
      "currency": "USD"},
      "description": "This is the payment transaction description."}]})

      if payment.create():
      print("Payment created successfully")

      for link in payment.links:
      if link.rel == "approval_url":
      # Convert to str to avoid Google App Engine Unicode issue
      # https://github.com/paypal/rest-api-sdk-python/pull/58
      approval_url = str(link.href)
      print("Redirect for approval: %s" % (approval_url))
      return HttpResponseRedirect(approval_url)
      else:
      print(payment.error)
      else:
      print('loading page')
      return render(request, 'app/payment.html')


      def success(request):
      //Here I also want to capture seller username and buyer username

      payment_id = request.GET.get('paymentId')
      payer_id = request.GET.get('PayerID')
      # Payment ID obtained when creating the payment (following redirect)
      payment = Payment.find(payment_id)

      # Execute payment with the payer ID from the create payment call (following redirect)
      if payment.execute({"payer_id": payer_id}):
      print("Payment[%s] execute successfully" % (payment.id))
      else:
      print(payment.error)

      return render(request, 'app/success.html')


      my payment.html payment template



      <html>
      <head>

      </head>


      <body>
      <h3>Seller username:foo1 Buyer username:foo2</h3>

      <form action='{% url "app:payment_page" %}' method='post'>
      {% csrf_token %}
      <input type='submit' value='pay'>

      </form>
      </body>




      </html>






      python django paypal






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 20 at 14:17









      robert leerobert lee

      636




      636
























          1 Answer
          1






          active

          oldest

          votes


















          1














          I'm assuming you're using the PayPal REST API. Under the transaction object there is a field called note_to_payee which is returned on the response of the payment lookup.



          You can use that, or come up with some string format on the description and look for that.






          share|improve this answer
























          • Thank you :) I will give description a string format it looks like a good way to accomplish this

            – robert lee
            Jan 22 at 12:29











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54277358%2fhow-can-i-send-variables-to-paypal-api-and-get-them-back-with-python-sdk%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          I'm assuming you're using the PayPal REST API. Under the transaction object there is a field called note_to_payee which is returned on the response of the payment lookup.



          You can use that, or come up with some string format on the description and look for that.






          share|improve this answer
























          • Thank you :) I will give description a string format it looks like a good way to accomplish this

            – robert lee
            Jan 22 at 12:29
















          1














          I'm assuming you're using the PayPal REST API. Under the transaction object there is a field called note_to_payee which is returned on the response of the payment lookup.



          You can use that, or come up with some string format on the description and look for that.






          share|improve this answer
























          • Thank you :) I will give description a string format it looks like a good way to accomplish this

            – robert lee
            Jan 22 at 12:29














          1












          1








          1







          I'm assuming you're using the PayPal REST API. Under the transaction object there is a field called note_to_payee which is returned on the response of the payment lookup.



          You can use that, or come up with some string format on the description and look for that.






          share|improve this answer













          I'm assuming you're using the PayPal REST API. Under the transaction object there is a field called note_to_payee which is returned on the response of the payment lookup.



          You can use that, or come up with some string format on the description and look for that.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 22 at 11:10









          MátéMáté

          1,49631322




          1,49631322













          • Thank you :) I will give description a string format it looks like a good way to accomplish this

            – robert lee
            Jan 22 at 12:29



















          • Thank you :) I will give description a string format it looks like a good way to accomplish this

            – robert lee
            Jan 22 at 12:29

















          Thank you :) I will give description a string format it looks like a good way to accomplish this

          – robert lee
          Jan 22 at 12:29





          Thank you :) I will give description a string format it looks like a good way to accomplish this

          – robert lee
          Jan 22 at 12:29




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54277358%2fhow-can-i-send-variables-to-paypal-api-and-get-them-back-with-python-sdk%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Homophylophilia

          Updating UILabel text programmatically using a function

          Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage