You are here

class Braintree_WebhookTesting in Commerce Braintree 7

Hierarchy

Expanded class hierarchy of Braintree_WebhookTesting

File

braintree_php/lib/Braintree/WebhookTesting.php, line 2

View source
class Braintree_WebhookTesting {
  public static function sampleNotification($kind, $id) {
    $payload = base64_encode(self::_sampleXml($kind, $id));
    $signature = Braintree_Configuration::publicKey() . "|" . Braintree_Digest::hexDigest($payload);
    return array(
      'signature' => $signature,
      'payload' => $payload,
    );
  }
  private static function _sampleXml($kind, $id) {
    $subjectXml = self::_subscriptionSampleXml($id);
    $timestamp = self::_timestamp();
    return "\n        <notification>\n            <timestamp type=\"datetime\">{$timestamp}</timestamp>\n            <kind>{$kind}</kind>\n            <subject>{$subjectXml}</subject>\n        </notification>\n        ";
  }
  private static function _subscriptionSampleXml($id) {
    return "\n        <subscription>\n            <id>{$id}</id>\n            <transactions type=\"array\">\n            </transactions>\n            <add_ons type=\"array\">\n            </add_ons>\n            <discounts type=\"array\">\n            </discounts>\n        </subscription>\n        ";
  }
  private static function _timestamp() {
    $originalZone = date_default_timezone_get();
    date_default_timezone_set('UTC');
    $timestamp = strftime('%Y-%m-%dT%TZ');
    date_default_timezone_set($originalZone);
    return $timestamp;
  }

}

Members