Created
November 10, 2018 09:10
-
-
Save iammerus/0f924f865b24325b325ece09d21b12d7 to your computer and use it in GitHub Desktop.
Handling Paynow Status Updates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* First install the Paynow PHP Library using Composer | |
* | |
* You'll need to set the result url to https://yourapp/path/update.php | |
*/ | |
// Require in composer's autoloader | |
require_once 'path/to/vendor/autoload.php'; | |
// Create a new paynow object passing in your integration keys (used for validating the hash of the status update) | |
$paynow = new Paynow('INTEGRATION_ID', 'INTEGRATION_KEY', null, null); | |
try | |
{ | |
// Process the incoming status update | |
$status = $paynow->processStatusUpdate(); | |
// Get the reference of the transaction you sent with the transaction when you initiated it | |
// @see https://developers.paynow.co.zw/docs/sourcedocs_php.html#class-paynow-core-statusresponse | |
$reference = $status->reference(); | |
// Check if the transaction was paid for | |
if($status->paid()) | |
{ | |
// This user showed us dat doe. Better give them whatever they paid for | |
// On the real. Here you might want to update the transaction with the reference '$reference' | |
// in your DB. Set it's status as paid | |
} | |
else | |
{ | |
// We got some other status from Paynow. Handle that | |
// For the full list of the statuses that can be returned by Paynow, see https://developers.paynow.co.zw/docs/status_update.html | |
$state = $reference->status(); | |
// Update the transaction's status in your DB maybe? | |
} | |
} | |
catch (\Exception $e) | |
{ | |
// *scream* ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh | |
// something broke. log this? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment