Sanity Check Request - A Spin on Split Payment Implementation #6743
Replies: 4 comments 26 replies
-
@electricbamboo what gateway(s) are you expecting this implementation to work with? |
Beta Was this translation helpful? Give feedback.
-
Okay, how are they looking to differentiate the 2 donations? Would you be using something like our Funds add-on to send the "siteDonation" to a different fund or something? Also would the "siteDonation" be added to the same authorize account? _Ultimately what it sounds like your trying to do is process 2 donations during 1 form request - which is not currently possible out-of-the-box. _ I have a few options in mind that might work but would definitely require coding. Is it possible to do this only hitting the payment gateway once? |
Beta Was this translation helpful? Give feedback.
-
Hey Jon, Here are the relevant pieces of what I have going so far. The form loads and I'm able to drop in right at give_update_payment_status:
Originally, I had '$siteSupport = new Donation([.....' , but Donation isn't available in the function and throws an error. I suppose I could hardcode a require_once statement and reference the Donation Model (as well as Money and BillingAddress), but I know that's a terrible idea. I searched for all instances where you guys are using "$give->" to see if there was a "$give->ValueObjects" kind of object so I could do $give->value_objects->donation->new(...). I saw in class-give-payment.php where the $donation object is created from a fairly simple array:
So I dropped the "new Donation..." only to run into the same issue for the Money ValueObject. I suppose I could just use the same mechanics (round($total...etc)) you guys did there, but the fact that the Money::fromDecimal function takes in the currency as well implies there's some formatting going on I'd rather not try to work around. Is there a better way to be accessing these objects (or some documentation that I obviously need to read)? Questions
Thanks so much - I sincerely appreciate your guidance. Kind Regards, Avery |
Beta Was this translation helpful? Give feedback.
-
Thanks :) If you have a moment, I'm trying to implement something and, while I'm experiencing marginal success, I'd like to make sure I'm not missing something obvious. Take a look at the following screenshot: The idea is to give the admin the option to make the 'Add Donation to Site Support' choice for the donor, or pass the decision off on to them. So far, I've got the admin settings echoing to the front-end where I've got jQuery working to show/hide fields as appropriate, do the calculations, and save things to the donation meta. The issue is that I'm having trouble keeping the javascript for legacy forms from interfering with the javascript for the iframe-based forms as it causes some of the code to run twice (which is bad if you're, say, calculating a percentage of a donation amount and updating the donation amount field in javascript). I did see this: https://givewp.com/documentation/developers/conditionally-load-give-styles-and-scripts/ But I don't need to gut the whole GiveWP javascript engine - just tweak a small part. I borrowed the piece of using the wp_print_scripts hook and that sort of worked but the legacy js wasn't registering when it was supposed to and the multi-form/sequoia wasn't deregistering when it was supposed to. It just feels like it should work.
But as I alluded to above, that only worked for the iframe-based forms and stopped working altogether for the legacy form. At that point, the solution was to put everything into one js file and use jQuery('iframe[name="give-embed-form"]').contents().find('') to sort out whether or not I was in a legacy form or a sequoia one (which led to the aforementioned 'code running twice' issue). Question 1) ALL of the donor-selected values are being saved to the donation meta so I could be doing all of this on the server side. Should I be? Does it matter? Question 2) Is my thinking right concerning the js approach of putting everything in one file and abandoning trying to manage the registration and deregistration manually? Admittedly, putting all the js code in one place cleans up both the client and server side, but it means there's unused code in places and man using jQuery('iframe[name="give-embed-form"]').contents().find('') feels kind of hacky. I attached my js (js_update.txt) if you want to take a look (if not, totally cool - like I said, I've got this mostly working so I understand if you don't have time). Thanks for any input, thoughts, or direction, Avery |
Beta Was this translation helpful? Give feedback.
-
Hey guys,
No need for anyone to actually write anything code-wise, I'm just looking for someone to tell me "hey, that approach sounds reasonable" or "buddy, that's a fools-errand."
I have a client who is looking to implement something more or less in the ballpark of the attached screenshot (faithraiser_add_info_target). The idea is that in the payment flow the donor would have the option to give a percentage of the donation, or even a custom value donation, to the facilitating website (i.e. the website collecting the donations). My research wound me to the class-give-payment.php file (https://github.com/impress-org/givewp/blob/develop/includes/payments/class-give-payment.php) which in turn led me to the give_setup_payment hook.
I was thinking I could create a function that accepts the $this payment object as a parameter AND could access the new donate-to-the-site field(s) (i.e. are custom fields added to $payment or to some other variable?) and then hook it into the give_setup_payment hook. The function would copy most of the $this payment object into a new payment object, change the necessary fields (which I would want to confirm with you guys), and then process both simultaneously by adding it to the Give_Cache with a new ID.
I gather I would probably need to make the following changes to the payment objects:
$this (original payment object):
$siteDonation (new payment object):
Set ID and _ID
$siteDonation->ID = absint( $payment_id );
$siteDonation->_ID = absint( $payment_id );
Set donation info
$siteDonation ->total = $this->setup_total();
$siteDonation ->subtotal = $this->setup_subtotal();
$siteDonation ->currency = $this->setup_currency();
Setup gateway info
$siteDonation ->gateway = $this->setup_gateway();
$siteDonation ->transaction_id = $this->setup_transaction_id();
Set Other Identifiers to avoid conflicts with the original payment (I'm even less sure about these):
$siteDonation ->form_title = $this->setup_form_title();
$siteDonation ->form_id = $this->setup_form_id();
$siteDonation ->price_id = $this->setup_price_id();
$siteDonation ->key = $this->setup_payment_key();
$siteDonation ->number = $this->setup_payment_number();
Add the $siteDonation object to the Give_Cache:
Give_Cache::set_group( $siteDonation ->ID, get_object_vars( $siteDonation ), 'give-donations' );
Am I close? Thank you so much for reviewing this and pointing me in the right direction. Again, I'm not looking for anyone to write code for me. I just need to know 1) Can I win with this trajectory? and 2) How would I go about accessing the custom fields added either through Form Field Manager or elsewhere (I'm assuming this gets rolled into a 'meta' field in the $payment object, but I could be way off there). Thanks for the cairns :)
Kind Regards,
Avery
Also, the screenshot has the donor fields in the info part of the flow. I could move this to the Give Amount part of the flow if that would be easier.
Beta Was this translation helpful? Give feedback.
All reactions