Skip to content
This repository has been archived by the owner on Oct 12, 2019. It is now read-only.

Commit

Permalink
Add support for recurring payments
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrossie committed Feb 8, 2014
1 parent ee7be7a commit e530f6e
Show file tree
Hide file tree
Showing 3 changed files with 288 additions and 1 deletion.
15 changes: 15 additions & 0 deletions php/demo_website/createpaymentrequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,21 @@ function createPaymentRequest($params, &$formErrors)

}

if (isset($params['with_recurring_contract'])) {
$dataNoContract = $paymentRequest->serialize($codec);
$hashNoContract = hash('ripemd128', $dataNoContract);
$memcache->set($hashNoContract, $dataNoContract, FALSE, 60*60*24); /* cache for 24 hours */

$paymentRecurringPaymentDetails = new \payments\RecurringPaymentDetails();
$paymentRecurringPaymentDetails->payment_frequency_type = \payments\PaymentFrequencyType::MONTHLY;
$paymentRecurringPaymentDetails->max_payment_per_period = $totalAmount*1.0e8;
$paymentRecurringPaymentDetails->max_payment_amount = $totalAmount*1.0e8;
$paymentRecurringPaymentDetails->polling_url = AbsoluteURL('')."f.php?h=".$hashNoContract;
$details->setSerializedRecurringPaymentDetails($paymentRecurringPaymentDetails->serialize($codec));
$serialized = $details->serialize($codec);
$paymentRequest->setSerializedPaymentDetails($serialized);
}

$data = $paymentRequest->serialize($codec);

if (isset($params['produce_uri'])) {
Expand Down
1 change: 1 addition & 0 deletions php/demo_website/form.html.inc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ be from him!
</tr>

<tr><td>&nbsp;</td><td colspan="3"><input type="checkbox" name="produce_uri" id="produce_uri"/>Produce bitcoin: URI</td></tr>
<tr><td>&nbsp;</td><td colspan="3"><input type="checkbox" name="with_recurring_contract" id="with_recurring_contract"/>Set recurring</td></tr>

<tr><td>&nbsp;</td><td colspan="3"><input type="submit" name="submit" value="Create Payment Request"/></td></tr>

Expand Down
273 changes: 272 additions & 1 deletion php/demo_website/include/paymentrequest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
<?php
// DO NOT EDIT! Generated by Protobuf-PHP protoc plugin 0.9.4
// Source: paymentrequest.proto
// Date: 2013-04-17 18:43:15
// Date: 2014-02-08 18:09:40

namespace payments {

class PaymentFrequencyType extends \DrSlump\Protobuf\Enum {

This comment has been minimized.

Copy link
@kgreenek

kgreenek Feb 11, 2014

Instead of an enum, recommend just using a time interval to be more flexible.

const WEEKLY = 1;
const MONTHLY = 2;
const QUARTERLY = 3;
const ANNUAL = 4;
}
}
namespace payments {

class Output extends \DrSlump\Protobuf\Message {
Expand Down Expand Up @@ -146,6 +155,9 @@ class PaymentDetails extends \DrSlump\Protobuf\Message {
/** @var string */
public $merchant_data = null;

/** @var string */
public $serialized_recurring_payment_details = null;


/** @var \Closure[] */
protected static $__extensions = array();
Expand Down Expand Up @@ -212,6 +224,14 @@ public static function descriptor()
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$descriptor->addField($f);

// OPTIONAL BYTES serialized_recurring_payment_details = 8
$f = new \DrSlump\Protobuf\Field();
$f->number = 8;
$f->name = "serialized_recurring_payment_details";
$f->type = \DrSlump\Protobuf::TYPE_BYTES;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$descriptor->addField($f);

foreach (self::$__extensions as $cb) {
$descriptor->addField($cb(), true);
}
Expand Down Expand Up @@ -497,6 +517,43 @@ public function getMerchantData(){
public function setMerchantData( $value){
return $this->_set(7, $value);
}

/**
* Check if <serialized_recurring_payment_details> has a value
*
* @return boolean
*/
public function hasSerializedRecurringPaymentDetails(){
return $this->_has(8);
}

/**
* Clear <serialized_recurring_payment_details> value
*
* @return \payments\PaymentDetails
*/
public function clearSerializedRecurringPaymentDetails(){
return $this->_clear(8);
}

/**
* Get <serialized_recurring_payment_details> value
*
* @return string
*/
public function getSerializedRecurringPaymentDetails(){
return $this->_get(8);
}

/**
* Set <serialized_recurring_payment_details> value
*
* @param string $value
* @return \payments\PaymentDetails
*/
public function setSerializedRecurringPaymentDetails( $value){
return $this->_set(8, $value);
}
}
}

Expand Down Expand Up @@ -1224,3 +1281,217 @@ public function setMemo( $value){
}
}

namespace payments {

class RecurringPaymentDetails extends \DrSlump\Protobuf\Message {

/** @var string */
public $polling_url = null;

/** @var int - \payments\PaymentFrequencyType */
public $payment_frequency_type = null;

/** @var int */
public $max_payment_per_period = null;

/** @var int */
public $max_payment_amount = null;


/** @var \Closure[] */
protected static $__extensions = array();

public static function descriptor()
{
$descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'payments.RecurringPaymentDetails');

// REQUIRED STRING polling_url = 1
$f = new \DrSlump\Protobuf\Field();
$f->number = 1;
$f->name = "polling_url";
$f->type = \DrSlump\Protobuf::TYPE_STRING;
$f->rule = \DrSlump\Protobuf::RULE_REQUIRED;
$descriptor->addField($f);

// OPTIONAL ENUM payment_frequency_type = 2
$f = new \DrSlump\Protobuf\Field();
$f->number = 2;
$f->name = "payment_frequency_type";
$f->type = \DrSlump\Protobuf::TYPE_ENUM;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$f->reference = '\payments\PaymentFrequencyType';
$descriptor->addField($f);

// OPTIONAL UINT64 max_payment_per_period = 3
$f = new \DrSlump\Protobuf\Field();
$f->number = 3;
$f->name = "max_payment_per_period";
$f->type = \DrSlump\Protobuf::TYPE_UINT64;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$descriptor->addField($f);

// OPTIONAL UINT64 max_payment_amount = 4
$f = new \DrSlump\Protobuf\Field();
$f->number = 4;
$f->name = "max_payment_amount";
$f->type = \DrSlump\Protobuf::TYPE_UINT64;
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
$descriptor->addField($f);

foreach (self::$__extensions as $cb) {
$descriptor->addField($cb(), true);
}

return $descriptor;
}

/**
* Check if <polling_url> has a value
*
* @return boolean
*/
public function hasPollingUrl(){
return $this->_has(1);
}

/**
* Clear <polling_url> value
*
* @return \payments\RecurringPaymentDetails
*/
public function clearPollingUrl(){
return $this->_clear(1);
}

/**
* Get <polling_url> value
*
* @return string
*/
public function getPollingUrl(){
return $this->_get(1);
}

/**
* Set <polling_url> value
*
* @param string $value
* @return \payments\RecurringPaymentDetails
*/
public function setPollingUrl( $value){
return $this->_set(1, $value);
}

/**
* Check if <payment_frequency_type> has a value
*
* @return boolean
*/
public function hasPaymentFrequencyType(){
return $this->_has(2);
}

/**
* Clear <payment_frequency_type> value
*
* @return \payments\RecurringPaymentDetails
*/
public function clearPaymentFrequencyType(){
return $this->_clear(2);
}

/**
* Get <payment_frequency_type> value
*
* @return int - \payments\PaymentFrequencyType
*/
public function getPaymentFrequencyType(){
return $this->_get(2);
}

/**
* Set <payment_frequency_type> value
*
* @param int - \payments\PaymentFrequencyType $value
* @return \payments\RecurringPaymentDetails
*/
public function setPaymentFrequencyType( $value){
return $this->_set(2, $value);
}

/**
* Check if <max_payment_per_period> has a value
*
* @return boolean
*/
public function hasMaxPaymentPerPeriod(){
return $this->_has(3);
}

/**
* Clear <max_payment_per_period> value
*
* @return \payments\RecurringPaymentDetails
*/
public function clearMaxPaymentPerPeriod(){
return $this->_clear(3);
}

/**
* Get <max_payment_per_period> value
*
* @return int
*/
public function getMaxPaymentPerPeriod(){
return $this->_get(3);
}

/**
* Set <max_payment_per_period> value
*
* @param int $value
* @return \payments\RecurringPaymentDetails
*/
public function setMaxPaymentPerPeriod( $value){
return $this->_set(3, $value);
}

/**
* Check if <max_payment_amount> has a value
*
* @return boolean
*/
public function hasMaxPaymentAmount(){
return $this->_has(4);
}

/**
* Clear <max_payment_amount> value
*
* @return \payments\RecurringPaymentDetails
*/
public function clearMaxPaymentAmount(){
return $this->_clear(4);
}

/**
* Get <max_payment_amount> value
*
* @return int
*/
public function getMaxPaymentAmount(){
return $this->_get(4);
}

/**
* Set <max_payment_amount> value
*
* @param int $value
* @return \payments\RecurringPaymentDetails
*/
public function setMaxPaymentAmount( $value){
return $this->_set(4, $value);
}
}
}

0 comments on commit e530f6e

Please sign in to comment.