Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I have setup a form where user fill some fields and choose a user type & on submission I have to send him to paypal with the values which he filled up, so that on IPN callback I receive the data from them and do something(this is the procedure I have come to know from reading paypal integration with php), I am stuck at form point because at submission I have another function where I can get the selected value by form_state..

Here is the code --

<?php

//Hook_Menu for paypal callback function.
function user_type_registration_menu(){
  $items = array();
          $items['paypal/payment/ipn'] = array(
          'title' => t('Paypal Payment IPN'),
          'description' => t('Paypal Payment IPN'),
          'type' => MENU_CALLBACK,
        'file'  => 'paypal_payment.inc',
          'page callback' => 'paypal_payment_paypal_ipn_callback',
          'access callback' => TRUE,
        );   
      return $items;
}

//Form alter for registration form.
function user_type_register_form_alter(&$form, &$form_state, $form_id){
  switch($form_id) {
      case 'user_register_form': // the value we stole from the rendered form
        $form['account']['user_type'] = array(
          '#type' => 'select',
          '#title' => t('Membership Type:'),
          '#options' => array(
            0 => t('General $50.00/Yr'),
            1 => t('Student $40.00/Yr'),
            2 => t('Government $60.00/Yr'),
            ),
           '#weight' => -11,
           '#description' => t('Select the membership type, which you want to have.'),
          );        
        $form['account']['user_type_submit'] = array(
          '#type' => 'submit',
          '#value' => t('Submit'),
          '#submit' => array('user_type_register_form_submit'),
          '#validate' => array('user_type_register_form_alter_validate'),
        );        
        $form['account']['name']['#description'] = t('');
        $form['account']['mail']['#description'] = t('');
        unset ($form['actions']);// unset the default submit Button      
        return $form;
      break;
    }   
}

function user_type_register_form_submit($form, &$form_state){  
  $username = $form_state['values']['name'];
  $user_email = $form_state['values']['mail'];
  $user_type = $form_state['values']['user_type'];
  $password = user_password(8);
  switch($user_type){

    case '0':
      dpm("General");
      $membership_price = 50;
      $fields = array(
        'name' => $username,
        'mail' => $user_email,
        'pass' => $password,
        'status' => 1,
        'init' => $user_email,
        'roles' => array(
          DRUPAL_AUTHENTICATED_RID => 'authenticated user',),
      );
      $account = user_save('', $fields);
      $account->password = $fields['password'];
      //--Here I have to send if to PAYPAL

      dpm("user registered");
      break;

    case '1':
      dpm("Student");
      $membership_price = 40;
      $fields = array(
        'name' => $username,
        'mail' => $user_email,
        'pass' => $password,
        'status' => 1,
        'init' => $user_email,
        'roles' => array(
          DRUPAL_AUTHENTICATED_RID => 'authenticated user',),
      );
      $account = user_save('', $fields);
      $account->password = $fields['password'];
      //--Here I have to send if to PAYPAL
      break;

    case '2':
      dpm("Government");
      $membership_price = 60;
      $fields = array(
        'name' => $username,
        'mail' => $user_email,
        'pass' => $password,
        'status' => 1,
        'init' => $user_email,
        'roles' => array(
          DRUPAL_AUTHENTICATED_RID => 'authenticated user',),
      );
      $account = user_save('', $fields);
      $account->password = $fields['password'];
      //--Here I have to send if to PAYPAL
      break;
  }
}

function user_type_register_form_alter_validate(){

}

I hope somebody can help...

share|improve this question

migrated from stackoverflow.com Feb 4 '13 at 4:00

This question came from our site for professional and enthusiast programmers.

3 Answers 3

I'm the maintainer of Drupal Commerce and of the Commerce PayPal module. I'm afraid your question is too broad to be answerable here, but for folks looking to solve the same issue, you should check out the code in my Commerce PayPal module. It provides a full integration of WPS, WPP, EC, and PPA / Payflow Link.

For general Drupal support, there are much better channels to pursue. I'd look into videos or books specifically focusing on the Forms API or just dive into module code like mine to learn through investigating working examples.

share|improve this answer

I believe Ryan is right, since your question is a bit too generic.
Still, I believe the way to try and handle those kind of tasks should be via the integration between Drupal, Commerce and Rules.

In a use case I had, I wanted to achieve some kind of user subscription for a node. To make this happen, I wrote some basic building blocks I believe you can re-use in your situation.

Full details is here, and the specific module to handle IPN via Rules is here. Hope this helps, and I will be happy to help more if needed.
Regards,
Shushu

share|improve this answer

I don't believe that you need to introduce yourself here at drupal.stackexchange, who doesn't know who Ryan is if a person is working with Drupal ?

I have very simple need. On the user registration page there is a select box for 3-4 membership type. User will fill the form, select a membership type and click submit to pay by paypal. Will be forwarded to paypal...and on payment he will return back on site. He will see him registered.

At first when this requirement came, I thought it could be easy to achieve with drupal commerce as I have used your module. But I couldn't find any way to do this simple thing. I don't have shame to say that...I am not any good at rules module(specially PHP logics to write for something). I ruined two days searching some option...trying this & that. Though I found one promising paid module name MEMBERSHIP SUITE to achieve the same, but it charge on yearly basis. Then again I went through the requirement & thought...why can't I do it by own module...I will have to alter the form, change action & send him to paypal to pay..When he returns back, I will register him in callback function.

This thing is done for now...for which I asked earlier & you have answered.

Now I am struggling with the IPN callback as it's not returning me any values which I have sent & always returning INVALID(I am working with sandbox though).

I haven't done this before & so that struggling...but I believe, this is how I will learn...

At last -- I AM BIG FAN OF YOURS & it was nice seeing you replying my post..

Thanks

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.