OctoDev Posted November 8, 2021 Posted November 8, 2021 Does anyone know how I could hook into the 'Approve' button in Transactions? So when I click approve, it would also send a request to my payment api to approve it if set in review. Was hoping there would be an alternative to public function refund( \IPS\nexus\Transaction $transaction, $amount = NULL ) but for approval
Daniel F Posted November 8, 2021 Posted November 8, 2021 You could hook into \IPS\nexus\Transaction::approve() OctoDev 1
OctoDev Posted November 10, 2021 Author Posted November 10, 2021 On 11/8/2021 at 5:39 PM, Daniel F said: You could hook into \IPS\nexus\Transaction::approve() Understood, however I want to do it at the webhook. So my webhook would send "approve" then it would approve the payment also on IPS. How is that possible? This one, would allow me to reverse it. By sending an API call to my PAyment API. I want it other way around.
Daniel F Posted November 10, 2021 Posted November 10, 2021 I'm confused. You mentioned that you want to customize the behavior when the approve button in your ACP is clicked. Quote So when I click approve, it would also send a request to my payment api to approve it There's unfortunately no REST API endpoint in IPS to change the invoice or transaction status.
OctoDev Posted November 10, 2021 Author Posted November 10, 2021 (edited) 7 minutes ago, Daniel F said: I'm confused. You mentioned that you want to customize the behavior when the approve button in your ACP is clicked. There's unfortunately no REST API endpoint in IPS to change the invoice or transaction status. Not looking for REST. Within my webhook, I have this. How can I do STATUS_APPROVED for example? https://secupload.io/file/FQeKbY Edited November 10, 2021 by OctoDev
IPCommerceFan Posted November 10, 2021 Posted November 10, 2021 It appears STATUS_PAID is the closest thing to STATUS_APPROVED short of adding a new status yourself. e.g. const STATUS_PAID = 'okay'; // Transaction has been paid successfully const STATUS_PENDING = 'pend'; // Payment not yet submitted (for example, has been redirected to external site) const STATUS_WAITING = 'wait'; // Waiting for user (for example, a check is in the mail). Manual approval will be required const STATUS_HELD = 'hold'; // Transaction is being held for approval const STATUS_REVIEW = 'revw'; // Transaction, after being held for approval, has been flagged for review by staff const STATUS_REFUSED = 'fail'; // Transaction was refused const STATUS_REFUNDED = 'rfnd'; // Transaction has been refunded in full const STATUS_PART_REFUNDED = 'prfd'; // Transaction has been partially refunded const STATUS_GATEWAY_PENDING= 'gwpd'; // The gateway is processing the transaction const STATUS_DISPUTED = 'dspd'; // The customer disputed the transaction with their bank (filed a chargeback) const STATUS_APPROVED = 'appr'; // Added for additional status functionality and then of course you'd have to decide how/when the status would be set. As it stands though, the suite seems to treat PAID as being synonymous with APPROVED. For instance, the sendNotification() funciton in \IPS\nexus\Transaction lists the notification key for STATUS_PAID as 'transactionApproved'.
OctoDev Posted November 10, 2021 Author Posted November 10, 2021 6 hours ago, IPCommerceFan said: It appears STATUS_PAID is the closest thing to STATUS_APPROVED short of adding a new status yourself. e.g. const STATUS_PAID = 'okay'; // Transaction has been paid successfully const STATUS_PENDING = 'pend'; // Payment not yet submitted (for example, has been redirected to external site) const STATUS_WAITING = 'wait'; // Waiting for user (for example, a check is in the mail). Manual approval will be required const STATUS_HELD = 'hold'; // Transaction is being held for approval const STATUS_REVIEW = 'revw'; // Transaction, after being held for approval, has been flagged for review by staff const STATUS_REFUSED = 'fail'; // Transaction was refused const STATUS_REFUNDED = 'rfnd'; // Transaction has been refunded in full const STATUS_PART_REFUNDED = 'prfd'; // Transaction has been partially refunded const STATUS_GATEWAY_PENDING= 'gwpd'; // The gateway is processing the transaction const STATUS_DISPUTED = 'dspd'; // The customer disputed the transaction with their bank (filed a chargeback) const STATUS_APPROVED = 'appr'; // Added for additional status functionality and then of course you'd have to decide how/when the status would be set. As it stands though, the suite seems to treat PAID as being synonymous with APPROVED. For instance, the sendNotification() funciton in \IPS\nexus\Transaction lists the notification key for STATUS_PAID as 'transactionApproved'. Status paid does not seem to work for me, not sure why. But the transaction is still pending approval.
IPCommerceFan Posted November 10, 2021 Posted November 10, 2021 Just browsing through nexus\interface\gateways\paypal, it looks like you need to set the status when you save the transaction. if ($status == 'paid') { // payment is complete if ( $transaction->status !== \IPS\nexus\Transaction::STATUS_PAID ) { $transaction->gw_id = $transactionId; $transaction->auth = NULL; $transaction->approve(); $transaction->status = \IPS\nexus\Transaction::STATUS_PAID; $transaction->save(); $transaction->sendNotification(); } } It seems $transaction->approve() SHOULD do this for you, but if its not, I'd try doing it explicitly like its done in the paypal gateway. Maybe approve isn't doing it due to declaring "->approve(NULL)" as opposed to "->approve()"? Incidentally (and feel free to ignore this section), I'm curious what some kind of debugging would capture at each step. One method I use is adding a function that looks something like this to the class I want to debug: /** * Debugging Tool * * @param __LINE__ $magicLine Line in code * @param __FUNCTION__ $magicFunction Function in code * @param string $desc Unique descriptive text * @param mixed $markerData Data we want to capture * @return void */ static public function codeMarker( $magicLine, $magicFunction, $desc=NULL, $markerData=NULL ) { $hookID = ''; $filename = 'phpFilename'; \IPS\Db::i()->insert('dbg_table', array( 'debug_hook_id' => $hookID, 'debug_hook_filename' => $filename, //'debug_hook_plugin' => \IPS\Application::load(\IPS\Plugin\Hook::load( $hookID )->app)->directory, 'debug_hook_plugin' => 'pluginName', 'debug_line_number' => $magicLine, 'debug_function_name' => $magicFunction, 'debug_description' => $desc, 'debug_markerdata' => \is_array($markerData) ? substr(json_encode($markerData),0,2048) : $markerData, 'debug_timestamp' => str_pad(microtime(time()),15,"0",STR_PAD_RIGHT) )); } Then add "code markers" to the code, run it, and see what turns up. In this case I would hook into \IPS\nexus\Transaction::approve() and add: static::codeMarker(__LINE__,__FUNCTION__,'_check_status_before_', $this->status); parent::approve(); static::codeMarker(__LINE__,__FUNCTION__,'_check_status_after_', $this->status); Or even redeclare the function verbatim and insert markers as desired. Then query the debug table to see what we caught. I'm not sure that this is an accepted or even a remotely efficient way of debugging, but its what works for me (better than error_log, debug_backtrace, etc since we are inserting markers directly into the code at the spot we want to inspect)
Recommended Posts