Feature request: PayPal Button form filter

We have a single PayPal account that we use for multiple e-commerce stores/applications, and we need a way, in PayPal, to identify which site/application the transaction came from. For cart-based applications, we can do this by careful construction of SKUs and invoice numbers, but PayPal Buttons are generic and otherwise offer no identification of their source.

I'd like an action I can hook to emit extra fields (such as on0/os1) into the PayPal Button form. The obvious place for this is paypalexpress::common_button_fields().

If you accept them, I'll happily submit a patch that does this, and I'd rather not have to patch the plugin sources every new release you make.

  • David King

    Many thanks for the points. Re the dev team being busy, I grok, I grok!

    Initial experiments suggest that the patch would be very small: just one line change in each of

    membership/membershipincludes/gateways/gateway.paypalexpress.php
    membership/membershipincludes/gateways/gateway.paypalsolo.php

    but I have not yet had a chance to test this modification with PayPal sandbox, so can't be definitive on that. A preliminary patch, however, would look like this:

    --- gateway.paypalexpress.php.orig      2015-04-22 12:24:29.747811259 -0500
    +++ gateway.paypalexpress.php   2015-04-22 12:26:09.688131769 -0500
    @@ -615,7 +615,7 @@
                    // don't ask for a shipping address
                    $form .= '<input type="hidden" name="no_shipping" value="1" />';
    
    -               return $form;
    +               return apply_filters( 'membership_paypal_button_fields', $form );
            }
    
            function build_subscribe_button( $subscription, $pricing, $user_id ) {
    @@ -1205,4 +1205,4 @@
    
     }
  • David King

    Update to this in light of release of Memberships 2 Pro: the current version (1.0.0.7) supplies a standard filter called ms_gateway_paypalstandard_view_prepare_fields which can be used for this or similar purposes.

    Example: We want to prepend a business unit identifier to the item_number field (to make it easier to reconcile PayPal statements with our accounting package). The following code achieves that:

    /* Prepend business unit name to button field "item_number" */
    add_filter( 'ms_gateway_paypalstandard_view_prepare_fields', 'membership_button_custom_fields' );
    function membership_button_custom_fields( $fields ) {
            $fields['item_number']['value'] = BUS_UNIT_ID_MEMBERSHIP . $fields['item_number']['value'];
            return $fields;
    }

    (Closing this thread.)