Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. function payment_method_paypal_conf(){
  2. if(arg(2) && is_numeric(arg(2))){
  3. $uid = arg(2);
  4. }
  5. else if(arg(3) && is_numeric(arg(3))){
  6. $uid = arg(3);
  7. }
  8. else{
  9. global $user;
  10. $uid = $user->uid;
  11. }
  12.  
  13. $check = db_select('afl_usr_payment_methods' , 'method')
  14. ->fields('method', array('method'))
  15. ->condition('method', 'method_paypal', '=')
  16. ->condition('uid', $uid, '=')
  17. ->condition('status', 1, '=')
  18. ->execute()->rowCount();
  19.  
  20.  
  21. if(! $check){
  22. drupal_set_message(t('The payment method: Paypal is not enabled'), 'info');
  23. drupal_goto('afl/payment-methods');
  24. }
  25.  
  26. $data = db_select('afl_usr_payment_methods' , 'method')
  27. ->fields('method', array('data'))
  28. ->condition('method', 'method_paypal', '=')
  29. ->condition('uid', $uid, '=')
  30. ->condition('status', 1, '=')
  31. ->execute()->fetchField();
  32. $afl_available_payment_methods = afl_variable_get('afl_available_payment_methods', '');
  33. $afl_approved_payment_methods = afl_variable_get('afl_approved_payment_methods', '');
  34. $approved_payment_methods = array();
  35. if(! empty($afl_available_payment_methods)){
  36. $afl_available_payment_method_array = list_extract_allowed_values($afl_available_payment_methods,'list_text',FALSE);
  37. $payment_val = $afl_available_payment_method_array['method_paypal'];
  38. $afl_available_payment_method_splits = explode('###', $payment_val);
  39. $afl_available_payment_fields = explode('&', $afl_available_payment_method_splits[1]);
  40. $field_val = drupal_json_decode($data);
  41. foreach($afl_available_payment_fields as $fileds){
  42. $fileds_prop = explode('*', $fileds);
  43. $field_key = $fileds_prop[0];
  44. $form[$field_key]= array(
  45. '#type' => 'textfield',
  46. '#required' => TRUE,
  47. '#title' => t($fileds_prop[1]),
  48. '#default_value' => isset($field_val[$field_key]) ? $field_val[$field_key] : '',
  49. );
  50. }
  51.  
  52. }
  53.  
  54. $form['method_uid']= array(
  55. '#type' => 'hidden',
  56. '#value' => $uid,
  57. );
  58.  
  59. $form['submit']= array(
  60. '#type' => 'submit',
  61. '#value' => t('Save Payment methods'),
  62. );
  63.  
  64. return $form;
  65. }
  66.  
  67.  
  68. function payment_method_paypal_conf_submit($form, &$form_state){
  69. $val = $form_state['values'];
  70. $q = db_update('afl_usr_payment_methods')
  71. ->fields(array('data' => drupal_json_encode($val), 'completed' => 1))
  72. ->condition('method', 'method_paypal', '=')
  73. ->condition('uid', check_plain($val['method_uid']), '=')
  74. ->execute();
  75. if ($q) {
  76. drupal_set_message(t('Your Paypal details saved successfully.'), 'status');
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement