Containing Bitcoin IPN (Bitcoin Instant Payment Notification)
CakePHP 2.x
app/Plugin/Payment
CakePlugin::load()
statement or use CakePlugin::loadAll()
Run
$ cake schema create payment -plugin payment
Provide a config array in your configs: $config['Bitcoin'] = array(..) with your preferences and credentials
If you want to use the built in admin access to IPNs:
www.yoursite.com/admin/payment/bitcoin
Create a function in your /app/AppModel.php
like so:
public function afterBitcoinNotification($txnId){
//Here is where you can implement code to apply the transaction to your app.
//for example, you could now mark an order as paid, a subscription, or give the user premium access.
//retrieve the transaction using the txnId passed and apply whatever logic your site needs.
$transaction = ClassRegistry::init('Payment.BitcoinAddress')->findById($txnId);
$this->log($transaction['BitcoinAddress']['id'], 'bitcoin');
if(...) {
//Yay! We have the money!
} else {
//Oh no, not enough... better look at this transaction to determine what to do; like email a decline letter.
}
}
Add Payment.Bitcoin
to your helpers list in AppController.php
public $helpers = array('Html','Form','Payment.Bitcoin');
$this->Bitcoin->image(64);
$this->Bitcoin->paymentBox(12.3, YOUR_ADDRESS);
As tempting as it was to integrate the Paypal IPN Plugin which this plugin is based on, I decided not to do this at the moment. This way they can be maintained separately. Not only this plugin but also the technology/protocol itself is under heavy maintenance and still changing from time to time.
It could become a complete "Payment" plugin combining all methods and services one day...
I spent quite a few days developing this plugin and testing all features. Feel free to donate if you use this plugin
Enjoy!