Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. <?php
  2. /**
  3. * Plugin Name: Give - Free
  4. **/
  5.  
  6. /**
  7. * Register our plugin so it shows up as an option in the Give gateway settings
  8. */
  9. add_filter( 'give_payment_gateways', function() {
  10. // Here replace 'give_free' with a unique slug for your plugin. You will use this slug throughout this plugin.
  11. $gateways['give_free'] = array(
  12. 'admin_label' => esc_attr__( 'Free', 'give-free' ),
  13. 'checkout_label' => esc_attr__( 'Free', 'give-free' )
  14. );
  15. return $gateways;
  16. } );
  17.  
  18. /**
  19. * This action will run the function attached to it when it's time to process the donation submission.
  20. *
  21. * Here you use the slug you made above at the end of the action name, give_gateway_YOUR_SLUG
  22. **/
  23. add_action( 'give_gateway_give_free', function( $purchase_data ) {
  24. $payment_data = array(
  25. 'price' => $purchase_data['price'],
  26. 'give_form_title' => $purchase_data['post_data']['give-form-title'],
  27. 'give_form_id' => intval( $purchase_data['post_data']['give-form-id'] ),
  28. 'give_price_id' => isset( $purchase_data['post_data']['give-price-id'] ) ? $purchase_data['post_data']['give-price-id'] : '',
  29. 'date' => $purchase_data['date'],
  30. 'user_email' => $purchase_data['user_email'],
  31. 'purchase_key' => $purchase_data['purchase_key'],
  32. 'currency' => give_get_currency(),
  33. 'user_info' => $purchase_data['user_info'],
  34. 'status' => 'pending', /** THIS MUST BE SET TO PENDING TO AVOID PHP WARNINGS */
  35. 'gateway' => 'give_free' /** USE YOUR SLUG AGAIN HERE */
  36. );
  37.  
  38. /**
  39. * Here you will reach out to whatever payment processor you are building for and record a successful payment
  40. *
  41. * If it's not correct, make $payment false and attach errors
  42. */
  43.  
  44. // record the payment which is super important so you have the proper records in the Give administration
  45. $payment = give_insert_payment( $payment_data );
  46.  
  47. if ( $payment ) {
  48. give_update_payment_status( $payment, 'publish' ); /** This line will finalize the donation, you can run some other verification function if you want before setting to publish */
  49. give_send_to_success_page();
  50. } else {
  51. // if errors are present, send the user back to the donation form so they can be corrected
  52. give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] );
  53. }
  54. } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement