Support » Plugin: Give - Donation Plugin and Fundraising Platform » Create a new gateway?

  • Resolved wibergsweb

    (@wibergsweb)


    Hi

    I figured out some hooks to use to implement a new gateway into the WP Give plugin:

    (This code is in an new plugin)
    add_filter(‘give_payment_gateways’, array( $this, ‘swish_payment’ ) );
    add_action( ‘give_swish_cc_form’, ‘__return_false’ );
    add_action(‘give_gateway_swish’, array( $this, ‘payment_data’) );

    but how do I for example add a settings tab WITHOUT hardcording into class-metabox-forms-data.php in the includes/admin/forms folder?

    what actions/filters are needed for the whole payment process to work? (With these actions/filter above I only to get to a blank page)

    • This topic was modified 3 months ago by  wibergsweb.
    • This topic was modified 3 months ago by  wibergsweb.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Ben Meredith

    (@benmeredithgmailcom)

    Hi @wibergsweb,

    Thanks for reaching out, and for extending Give! That’s super exciting.

    The easiest way to understand how to add a payment gateway is to mimic the default behavior of another payment gateway, which is functionally what the files at give/includes/gateways/ do. The manual.php file is a good starting point, and the paypal-standard.php is also a great way to get started there. Our friend Chris Flannagan also wrote this low-level tutorial on creating a new gateway here: https://whoischris.com/building-payment-gateway-give-wp-donation-plugin-wordpress/

    Also, have you joined our Facebook community at https://www.facebook.com/groups/givewp/ ? The other developers in that group may be able to give you some insight into your question.

    Quickly in reference to your specific questions, the settings pages have hooks to be able to hook into for displaying things, and classes to extend to add additional elements.

    The class-metabox-forms-data.php file doesn’t deal with the settings tabs at all. That would instead be used for modifying the metabox displayed at Donations > Forms in the Dashboard.

    To add a whole new settings tab, you’d extend the Give_Settings_Page class.

    Specifically, to add the Payment Gateway information for a new gateway within the settings tab, you’d use the filter ‘give_get_settings_gateways’ to add the gateway within the gateways tab.

    Thanks for extending Give!

    wibergsweb

    (@wibergsweb)

    Thanks a lot!

    I have checked out those existing gateways already, but I missed out on the filter give_gateway_swish. In the function I had a return true but that just made the wordpress stop with no errors.

    I just put in the payment data and did not do any insertion of data:

    This was required (I don’t know why I missed this but in case anyone else have same question this might be a clue!)

    // record the pending payment (or failed)
    $payment = give_insert_payment( $payment_data );

    if ( $payment ) {
    give_update_payment_status( $payment, ‘publish’ );
    give_send_to_success_page();
    } else {
    give_record_gateway_error(
    esc_html__( ‘Payment Error’, ‘give’ ),
    sprintf(
    /* translators: %s: payment data */
    esc_html__( ‘The payment creation failed while processing a donation. Payment data: %s’, ‘give’ ),
    json_encode( $payment_data )
    ),
    $payment
    );
    // If errors are present, send the user back to the donation page so they can be corrected
    give_send_back_to_checkout( ‘?payment-mode=’ . $purchase_data[‘post_data’][‘give-gateway’] );
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.