Hướng dẫn thêm PayPal Button to your Drupal Webform - Drupal 9

Hướng dẫn thêm PayPal Button to your Drupal Webform - Drupal 9

Recently, a client of mine asked me to add a PayPal button to his website. He wanted to add a sign up form for a Trial Membership along with a PayPal button to make a small payment. So I searched on Drupal.org and found some custom PHP code that works very well. You will need to have an active PayPal account and some knowledge of PHP programming to follow this tutorial.

Things to Do:

1. Choose an email address and sign up for an account at PayPal so you can receive credit card payments online.

2. Go into your PayPal Account settings and set the correct currency for the payment.

3. Write down the following:

  • Item Name: 
  • Item Number:
  • For our example, we used Trial Membership for Item Name and SKU012 for Item Number.

On Your Drupal Website:

4. Create your webform in Drupal with a Student name, Item cost, Phone number and other fields you need.

5. Write down the machine names for your  fields, Student Name and Item Cost. These will be the variable names in the custom PHP code shown below. Replace $name_of_student and $trial_class_cost with your variable names.

6. Edit the Student Name form field and look at the URL. You will find the component number listed there.

For example, for the Trial Class Cost field, the URL is node/104/webform/components/9?destination=node%2F104%2Fwebform and the component number is 9. This goes here:

$trial_class_cost = $submission->data[9]['value'][0];

Be sure to put the correct component numbers for Student Name and Trial Class Cost

7. Add the following code to the Confirmation Message textarea. Be sure to disable your WYSIWYG editor for this textarea. CKeditor will turn the PHP code in your HTML form to garbage code.

<?php include_once(drupal_get_path('module', 'webform') .'/includes/webform.submissions.inc');
$nid = arg(1); // need to hard-code nid if this is a custom page
$sid = $_GET['sid']; $submission = webform_get_submission($nid, $sid);
$name_of_student = $submission->data[1]['value'][0];
$thanks = $name_of_student;
$trial_class_cost = $submission->data[9]['value'][0];
$total_to_pay = $trial_class_cost; ?>

<h2> Thank you <?php print $thanks ?> for submitting your registration.</h2>

<ul> <li class="trial-pay-text">Click "Buy Now" to finalize your registration.</li>
<li class="trial-pay-text"> Important: Print out your PayPal payment as a receipt.</li> </ul>

<h4> Trial Membership (including HST): $<?php print $total_to_pay; ?></h4>

<ul> <li> <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input name="cmd" type="hidden" value="_xclick" />
<input name="business" type="hidden" value="[email protected]" />
<input name="item_name" type="hidden" value="Trial Membership" />
<input name="item_number" type="hidden" value="SKU012" />
<input name="amount" type="hidden" value="<?php print $total_to_pay; ?>" />
<input name="bn" type="hidden" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest" />
<input alt="PayPal - The safer, easier way to pay online!" border="0" name="submit" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" type="image" />
<img alt="" border="0" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" /></form> </li> </ul>
Bạn thấy bài viết này như thế nào?: 
Average: 5 (2 votes)
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Bình luận (0)

 

Add Comment

Filtered HTML

  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Các thẻ HTML được chấp nhận: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Tự động ngắt dòng và đoạn văn.

Plain text

  • No HTML tags allowed.
  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Tự động ngắt dòng và đoạn văn.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Apple đang phát triển máy nghe nhạc iPod đeo tay hỗ trợ Siri

Apple đang phát triển máy nghe nhạc iPod đeo tay hỗ trợ Siri

Apple có thể đang bí mật phát triển máy nghe nhạc iPod theo dạng vòng đeo tay có khả năng hỗ trợ đầy đủ chức năng nhận lệnh bằng giọng nói...

Tích hợp Facebook vào website

Tích hợp Facebook vào website

Tích hợp website của bạn với Facebook là một cách hay để xây dựng những con đường rộng mở dẫn vào "brand" của mình và làm cho website có vẻ sống động hơn.

Dùng thuốc diệt côn trùng để diệt côn trùng gây bệnh

Dùng thuốc diệt côn trùng để diệt côn trùng gây bệnh

Đối với hương muỗi hay thuốc xịt nên đốt, xịt thuốc trước 30 phút trước khi vào nhà. Sau khi xịt cần quét và gom lại để đốt tránh tình trạng muỗi sống lại và bay đi

Công ty diệt chuột T&C

 

Diet con trung