PayPal Integration

조회수 69회
읽지 않은 첫 메시지로 건너뛰기

Eric 247ERICPOINTCOM

읽지 않음,
2021. 5. 19. 오전 7:30:1321. 5. 19.
받는사람 Django users
Hi

I would like to integrate PayPal with my project in Django I have gone through a couple of tutorials but I still dont understand how to do it. I am new to Django but I have got a project am working on which charges per post on the website.

When a post is created it will be charged I want to add PayPal to the post button, so that when one pays the post is created automatically there after.

How can I do this.

Here is my template for create_post:

{% extends "feed/layout.html" %} {% load static %} {% load crispy_forms_tags %}
{% block searchform %}
<form
class="form-inline my-2 my-lg-0 ml-5"
action="{% url 'search_posts' %}"
method="get"
>
<input name="p" type="text" placeholder="Search posts.." />
<button class="btn btn-success my-2 my-sm-0 ml-4" type="submit">
Search
</button>
</form>
{% endblock searchform %} {% block content %}
<br /><br />
<div class="container">
<div class="row">
<div class="col-sm-9 col-md-7 col-lg-5 mx-auto">
<div class="card card-signin my-5">
<div class="card-body">
<h5 class="card-title text-center"><b>Post</b></h5>
<form class="form-signin" method="POST" enctype="multipart/form-data">
{% csrf_token %}
<fieldset class="form-group">
<br />
{{ form|crispy }}
</fieldset>
<div class="form-group">
<button
class="btn btn-lg btn-primary btn-block text-uppercase"
type="submit"
>
Post</button
><br />
</div>
</form>
</div>
</div>
</div>
</div>
</div>

{% endblock content %} {% block jsfiles %}{% endblock jsfiles %}

Sharif Mehedi

읽지 않음,
2021. 5. 19. 오전 10:23:3921. 5. 19.
받는사람 Django users
First you need to have OAuth 2 on your server. look for PYPI packages that has OAuth for paypal.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/46c1c5ea-d198-440f-8538-6d4955b237a8n%40googlegroups.com.

Eric 247ERICPOINTCOM

읽지 않음,
2021. 5. 19. 오후 1:27:1721. 5. 19.
받는사람 django...@googlegroups.com
Thank you Sharif. Let me do that, I will come back to the conversation after

Kind Regards


Eric Bawakuno | Computer Engineer | +27795639700+27 815152254 | eri...@gmail.com  | Address: 29 Rochester Road, Observatory | Cape Town, South Africa | 7925
f


Eric 247ERICPOINTCOM

읽지 않음,
2021. 5. 31. 오전 7:57:0321. 5. 31.
받는사람 django...@googlegroups.com
Thank you Sharif, I have integrated successfully with paypal after going through the paypal developer docs, and tested it with sandbox.paypal and it is working great.

However I would like your help, to now be able to submit  the form automatically after making the payment with paypal. I have tried adding type="submit"  to the paypal button but that doesn't work.  How can I do that?

Kind Regards


Eric Bawakuno | Computer Engineer | +27795639700+27 815152254 | eri...@gmail.com  | Address: 29 Rochester Road, Observatory | Cape Town, South Africa | 7925
f

Sharif Mehedi

읽지 않음,
2021. 5. 31. 오전 8:38:1621. 5. 31.
받는사람 django...@googlegroups.com
Glad to be of help.

It'd be easier for me to help you if I had a sneak peek at your code snippet, with which you are trying to do that.

Sharif

Eric 247ERICPOINTCOM

읽지 않음,
2021. 6. 1. 오후 2:31:4621. 6. 1.
받는사람 django...@googlegroups.com
Hi Sharif,

This is the code from the page I am trying to implement. It is a form which creates a post and the user will first pay by paypal, then after payment I would like the post of the user to be submitted automatically.

             <!--<button
                class="btn btn-lg btn-primary btn-block text-uppercase"
                type="submit">Post</button>-->

<div id="paypal-button"></div>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>
paypal.Button.render({
// Configure environment
env: 'sandbox',
client: {
sandbox: 'demo_sandbox_client_id',
production: 'demo_production_client_id'
},
// Customize button (optional)
locale: 'en_US',
style: {
size: 'responsive',
color: 'gold',
shape: 'pill',
label: 'pay',
tagline: 'true',
fundingicons: 'true',
},

// Enable Pay Now checkout flow (optional)
commit: true,

// Set up a payment
payment: function(data, actions) {
return actions.payment.create({
transactions: [{
amount: {
total: '15.00',
currency: 'USD'
}
}],

redirect_urls: {
return_url: 'https://example.com',
cancel_url: 'https://example.com'
}
});

},
experience: {
input_fields: {
no_shipping: 1
}
},



// Execute the payment
onAuthorize: function(data, actions) {
return actions.payment.execute().then(function() {
// Show a confirmation message to the buyer
window.alert('Thank you for your payment, your ad will be live now!');
});
},
onError: function (err) {
// Show an error page here, when an error occurs
},
onCancel: function (data, actions) {
// Show a cancel page or return to cart
window.alert('Your Payment Was Cancelled!');
},
}, '#paypal-button');

</script>



<br />
</div>
</form>
</div>
</div>
</div>
</div>
</div>

{% endblock content %}
{% block jsfiles %}{% endblock jsfiles %}

Thanks


Kind Regards


Eric Bawakuno | Computer Engineer | +27795639700+27 815152254 | eri...@gmail.com  | Address: 29 Rochester Road, Observatory | Cape Town, South Africa | 7925
f

Sharif Mehedi

읽지 않음,
2021. 6. 1. 오후 3:46:0121. 6. 1.
받는사람 django...@googlegroups.com
Okay,
You can use fetch, if you are not using any other javascript module you can do something like the following in onAuthorize method:
onAuthorize: function(data, actions) {
return actions.payment.execute().then(function() {
// Show a confirmation message to the buyer
window.alert('Thank you for your payment, your ad will be live now!')
;
        fetch(`${url}?data=${JSON.stringify(data)}`)
});
},
Here, the url should match one of your urls in the url_patterns and you get the data from the corresponding view and do whatever you like afterwards.
If you are interested in fetch, you can read all about it here: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API

Sharif

Eric 247ERICPOINTCOM

읽지 않음,
2021. 6. 1. 오후 4:51:1221. 6. 1.
받는사람 django...@googlegroups.com
Thanks Sharif,

Let me go through the document and try to use fetch, I will come back to the conversation after trying it out.

Kind Regards


Eric Bawakuno | Computer Engineer | +27795639700+27 815152254 | eri...@gmail.com  | Address: 29 Rochester Road, Observatory | Cape Town, South Africa | 7925
f

전체답장
작성자에게 답글
전달
새 메시지 0개