Commit f7ba23b3 authored by mattwire's avatar mattwire Committed by Matthew Wire

Load stripe-php via composer.

Always load stripe.js when on a payment processor page (recommended by stripe for fraud detection).
parent 520ed349
......@@ -333,8 +333,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
$parsed_url['query'] . "&_qf_Main_display=1&qfKey={$qfKey}", FALSE, NULL, FALSE);
}
// Include Stripe library then set plugin info and API credentials.
require_once('stripe-php/init.php');
// Set plugin info and API credentials.
\Stripe\Stripe::setAppInfo('CiviCRM', CRM_Utils_System::version(), CRM_Utils_System::baseURL());
\Stripe\Stripe::setApiKey($this->_paymentProcessor['user_name']);
......
......@@ -111,7 +111,6 @@ class CRM_Stripe_Page_Webhook extends CRM_Core_Page {
CRM_Utils_System::civiExit();
}
require_once ("packages/stripe-php/init.php");
\Stripe\Stripe::setAppInfo('CiviCRM', CRM_Utils_System::version(), CRM_Utils_System::baseURL());
\Stripe\Stripe::setApiKey($stripe_key);
......
<?php
require_once('packages/stripe-php/init.php');
/**
* Collection of upgrade steps.
* DO NOT USE a naming scheme other than upgrade_N, where N is an integer.
......
{
"require": {
"stripe/stripe-php": "^5.2"
}
}
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "2c17a82c0fb79b31818993eeb2df574d",
"packages": [
{
"name": "stripe/stripe-php",
"version": "v5.2.3",
"source": {
"type": "git",
"url": "https://github.com/stripe/stripe-php.git",
"reference": "9e8d565e991ca82c91d708b281063cefd69d7b2c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/stripe/stripe-php/zipball/9e8d565e991ca82c91d708b281063cefd69d7b2c",
"reference": "9e8d565e991ca82c91d708b281063cefd69d7b2c",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"satooshi/php-coveralls": "~0.6.1",
"squizlabs/php_codesniffer": "~2.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"autoload": {
"psr-4": {
"Stripe\\": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Stripe and contributors",
"homepage": "https://github.com/stripe/stripe-php/contributors"
}
],
"description": "Stripe PHP Library",
"homepage": "https://stripe.com/",
"keywords": [
"api",
"payment processing",
"stripe"
],
"time": "2017-09-27T20:35:23+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}
......@@ -5,6 +5,7 @@
<description>Stripe Payment Processor</description>
<urls>
<url desc="Main Extension Page">http://drastikbydesign.com</url>
<url desc="Support">https://www.mjwconsult.co.uk</url>
</urls>
<license>AGPL</license>
<maintainer>
......
......@@ -17,11 +17,11 @@
$(".messages.crm-error.stripe-message:first").remove();
}
$form.prepend('<div class="messages crm-error stripe-message">'
+ '<strong>Payment Error Response:</strong>'
+ '<ul id="errorList">'
+ '<li>Error: ' + response.error.message + '</li>'
+ '</ul>'
+ '</div>');
+ '<strong>Payment Error Response:</strong>'
+ '<ul id="errorList">'
+ '<li>Error: ' + response.error.message + '</li>'
+ '</ul>'
+ '</div>');
$submit.removeAttr('disabled').attr('value', buttonText);
......@@ -40,9 +40,7 @@
// Prepare the form.
$(document).ready(function() {
$.getScript('https://js.stripe.com/v2/', function () {
Stripe.setPublishableKey($('#stripe-pub-key').val());
});
Stripe.setPublishableKey($('#stripe-pub-key').val());
// Check for form marked as a stripe-payment-form by the server.
if (!($('form.stripe-payment-form').length)) {
......@@ -55,7 +53,7 @@
$('#crm-container > form').addClass('stripe-payment-form');
}
}
$form = $('form.stripe-payment-form');
if (isWebform) {
$submit = $form.find('.button-primary');
......@@ -183,7 +181,7 @@
}
}
else {
debugging('debug: qlmvy (Stripe is the only payprocessor here)');
debugging('debug: qlmvy (Stripe is the only payprocessor here)');
}
// Handle reuse of existing token
......@@ -229,7 +227,7 @@
}(cj, CRM));
function debugging (errorCode) {
// Uncomment the following to debug unexpected returns.
// console.log(errorCode);
// Uncomment the following to debug unexpected returns.
// console.log(errorCode);
}
language: php
php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
env:
- AUTOLOAD=1
- AUTOLOAD=0
script: ./build.php ${AUTOLOAD}
after_script: ./vendor/bin/coveralls -v
sudo: false
<?php
namespace Stripe;
/**
* Class Source
*
* @package Stripe
*/
class Source extends ApiResource
{
/**
* @param string $id The ID of the Source to retrieve.
* @param array|string|null $opts
*
* @return Source
*/
public static function retrieve($id, $opts = null)
{
return self::_retrieve($id, $opts);
}
/**
* @param array|null $params
* @param array|string|null $opts
*
* @return Collection of Sources
*/
public static function all($params = null, $opts = null)
{
return self::_all($params, $opts);
}
/**
* @param array|null $params
* @param array|string|null $opts
*
* @return Source The created Source.
*/
public static function create($params = null, $opts = null)
{
return self::_create($params, $opts);
}
/**
* @param array|null $params
* @param array|string|null $options
*
* @return BankAccount The verified bank account.
*/
public function verify($params = null, $options = null)
{
$url = $this->instanceUrl() . '/verify';
list($response, $opts) = $this->_request('post', $url, $params, $options);
$this->refreshFrom($response, $opts);
return $this;
}
}
<?php
namespace Stripe;
use Stripe\HttpClient\CurlClient;
class ApiRequestorTest extends TestCase
{
public function testEncodeObjects()
{
$reflector = new \ReflectionClass('Stripe\\ApiRequestor');
$method = $reflector->getMethod('_encodeObjects');
$method->setAccessible(true);
$a = array('customer' => new Customer('abcd'));
$enc = $method->invoke(null, $a);
$this->assertSame($enc, array('customer' => 'abcd'));
// Preserves UTF-8
$v = array('customer' => "☃");
$enc = $method->invoke(null, $v);
$this->assertSame($enc, $v);
// Encodes latin-1 -> UTF-8
$v = array('customer' => "\xe9");
$enc = $method->invoke(null, $v);
$this->assertSame($enc, array('customer' => "\xc3\xa9"));
}
public function testHttpClientInjection()
{
$reflector = new \ReflectionClass('Stripe\\ApiRequestor');
$method = $reflector->getMethod('httpClient');
$method->setAccessible(true);
$curl = new CurlClient();
$curl->setTimeout(10);
ApiRequestor::setHttpClient($curl);
$injectedCurl = $method->invoke(new ApiRequestor());
$this->assertSame($injectedCurl, $curl);
}
public function testDefaultHeaders()
{
$reflector = new \ReflectionClass('Stripe\\ApiRequestor');
$method = $reflector->getMethod('_defaultHeaders');
$method->setAccessible(true);
// no way to stub static methods with PHPUnit 4.x :(
Stripe::setAppInfo('MyTestApp', '1.2.34', 'https://mytestapp.example');
$apiKey = 'sk_test_notarealkey';
$headers = $method->invoke(null, $apiKey);
$ua = json_decode($headers['X-Stripe-Client-User-Agent']);
$this->assertSame($ua->application->name, 'MyTestApp');
$this->assertSame($ua->application->version, '1.2.34');
$this->assertSame($ua->application->url, 'https://mytestapp.example');
$this->assertSame(
$headers['User-Agent'],
'Stripe/v1 PhpBindings/' . Stripe::VERSION . ' MyTestApp/1.2.34 (https://mytestapp.example)'
);
$this->assertSame($headers['Authorization'], 'Bearer ' . $apiKey);
}
}
<?php
namespace Stripe;
class BitcoinReceiverTest extends TestCase
{
public function testUrls()
{
$classUrl = BitcoinReceiver::classUrl('Stripe_BitcoinReceiver');
$this->assertSame($classUrl, '/v1/bitcoin/receivers');
$receiver = new BitcoinReceiver('abcd/efgh');
$instanceUrl = $receiver->instanceUrl();
$this->assertSame($instanceUrl, '/v1/bitcoin/receivers/abcd%2Fefgh');
}
public function testCreate()
{
self::authorizeFromEnv();
$receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com");
$this->assertSame(100, $receiver->amount);
$this->assertNotNull($receiver->id);
}
public function testRetrieve()
{
self::authorizeFromEnv();
$receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com");
$r = BitcoinReceiver::retrieve($receiver->id);
$this->assertSame($receiver->id, $r->id);
$this->assertInstanceOf('Stripe\\BitcoinTransaction', $r->transactions->data[0]);
}
public function testList()
{
self::authorizeFromEnv();
$receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com");
$receivers = BitcoinReceiver::all();
$this->assertTrue(count($receivers->data) > 0);
}
public function testListTransactions()
{
self::authorizeFromEnv();
$receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com");
$this->assertSame(0, count($receiver->transactions->data));
$transactions = $receiver->transactions->all(array("limit" => 1));
$this->assertSame(1, count($transactions->data));
}
public function testDeleteWithCustomer()
{
self::authorizeFromEnv();
$receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com");
$customer = Customer::create(array("source" => $receiver->id));
$charge = Charge::create(array(
"customer" => $customer->id,
"amount" => $receiver->amount,
"currency" => $receiver->currency
));
$receiver = BitcoinReceiver::retrieve($receiver->id);
$response = $receiver->delete();
$this->assertTrue($response->deleted);
}
public function testUpdateWithCustomer()
{
self::authorizeFromEnv();
$receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com");
$customer = Customer::create(array("source" => $receiver->id));
$receiver = BitcoinReceiver::retrieve($receiver->id);
$receiver->description = "a new description";
$receiver->save();
$base = Customer::classUrl();
$parentExtn = $receiver['customer'];
$extn = $receiver['id'];
$this->assertEquals("$base/$parentExtn/sources/$extn", $receiver->instanceUrl());
$updatedReceiver = BitcoinReceiver::retrieve($receiver->id);
$this->assertEquals($receiver["description"], $updatedReceiver["description"]);
}
public function testUpdateWithoutCustomer()
{
self::authorizeFromEnv();
$receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com");
$receiver->description = "a new description";
$receiver->save();
$this->assertEquals(BitcoinReceiver::classUrl() . "/" . $receiver['id'], $receiver->instanceUrl());
$updatedReceiver = BitcoinReceiver::retrieve($receiver->id);
$this->assertEquals($receiver["description"], $updatedReceiver["description"]);
}
public function testRefund()
{
self::authorizeFromEnv();
$receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com");
$receiver = BitcoinReceiver::retrieve($receiver->id);
$this->assertNull($receiver->refund_address);
$refundAddress = "REFUNDHERE";
$receiver->refund(array("refund_address" => $refundAddress));
$this->assertSame($refundAddress, $receiver->refund_address);
}
}
<?php
namespace Stripe;
class TransferTest extends TestCase
{
public function testCreate()
{
$recipient = self::createTestRecipient();
self::authorizeFromEnv();
$transfer = Transfer::create(array(
'amount' => 100,
'currency' => 'usd',
'recipient' => $recipient->id
));
$this->assertSame('pending', $transfer->status);
}
public function testRetrieve()
{
$recipient = self::createTestRecipient();
self::authorizeFromEnv();
$transfer = Transfer::create(array(
'amount' => 100,
'currency' => 'usd',
'recipient' => $recipient->id
));
$reloaded = Transfer::retrieve($transfer->id);
$this->assertSame($reloaded->id, $transfer->id);
}
/**
* @expectedException Stripe\Error\InvalidRequest
*/
public function testCancel()
{
$recipient = self::createTestRecipient();
self::authorizeFromEnv();
$transfer = Transfer::create(array(
'amount' => 100,
'currency' => 'usd',
'recipient' => $recipient->id
));
$reloaded = Transfer::retrieve($transfer->id);
$this->assertSame($reloaded->id, $transfer->id);
$reloaded->cancel();
}
public function testTransferUpdateMetadata()
{
$recipient = self::createTestRecipient();
self::authorizeFromEnv();
$transfer = Transfer::create(array(
'amount' => 100,
'currency' => 'usd',
'recipient' => $recipient->id
));
$transfer->metadata['test'] = 'foo bar';
$transfer->save();
$updatedTransfer = Transfer::retrieve($transfer->id);
$this->assertSame('foo bar', $updatedTransfer->metadata['test']);
}
public function testTransferUpdateMetadataAll()
{
$recipient = self::createTestRecipient();
self::authorizeFromEnv();
$transfer = Transfer::create(array(
'amount' => 100,
'currency' => 'usd',
'recipient' => $recipient->id
));
$transfer->metadata = array('test' => 'foo bar');
$transfer->save();
$updatedTransfer = Transfer::retrieve($transfer->id);
$this->assertSame('foo bar', $updatedTransfer->metadata['test']);
}
public function testRecipientUpdateMetadata()
{
$recipient = self::createTestRecipient();
$recipient->metadata['test'] = 'foo bar';
$recipient->save();
$updatedRecipient = Recipient::retrieve($recipient->id);
$this->assertSame('foo bar', $updatedRecipient->metadata['test']);
}
public function testRecipientUpdateMetadataAll()
{
$recipient = self::createTestRecipient();
$recipient->metadata = array('test' => 'foo bar');
$recipient->save();
$updatedRecipient = Recipient::retrieve($recipient->id);
$this->assertSame('foo bar', $updatedRecipient->metadata['test']);
}
}
......@@ -2,6 +2,83 @@
// AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file
/**
* The ExtensionUtil class provides small stubs for accessing resources of this
* extension.
*/
class CRM_Stripe_ExtensionUtil {
const SHORT_NAME = "stripe";
const LONG_NAME = "com.drastikbydesign.stripe";
const CLASS_PREFIX = "CRM_Stripe";
/**
* Translate a string using the extension's domain.
*
* If the extension doesn't have a specific translation
* for the string, fallback to the default translations.
*
* @param string $text
* Canonical message text (generally en_US).
* @param array $params
* @return string
* Translated text.
* @see ts
*/
public static function ts($text, $params = array()) {
if (!array_key_exists('domain', $params)) {
$params['domain'] = array(self::LONG_NAME, NULL);
}
return ts($text, $params);
}
/**
* Get the URL of a resource file (in this extension).
*
* @param string|NULL $file
* Ex: NULL.
* Ex: 'css/foo.css'.
* @return string
* Ex: 'http://example.org/sites/default/ext/org.example.foo'.
* Ex: 'http://example.org/sites/default/ext/org.example.foo/css/foo.css'.
*/
public static function url($file = NULL) {
if ($file === NULL) {
return rtrim(CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME), '/');
}
return CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME, $file);
}
/**
* Get the path of a resource file (in this extension).
*
* @param string|NULL $file
* Ex: NULL.
* Ex: 'css/foo.css'.
* @return string
* Ex: '/var/www/example.org/sites/default/ext/org.example.foo'.
* Ex: '/var/www/example.org/sites/default/ext/org.example.foo/css/foo.css'.
*/
public static function path($file = NULL) {
// return CRM_Core_Resources::singleton()->getPath(self::LONG_NAME, $file);
return __DIR__ . ($file === NULL ? '' : (DIRECTORY_SEPARATOR . $file));
}
/**
* Get the name of a class within this extension.
*
* @param string $suffix
* Ex: 'Page_HelloWorld' or 'Page\\HelloWorld'.
* @return string
* Ex: 'CRM_Foo_Page_HelloWorld'.
*/
public static function findClass($suffix) {
return self::CLASS_PREFIX . '_' . str_replace('\\', '_', $suffix);
}
}
use CRM_Stripe_ExtensionUtil as E;
/**
* (Delegated) Implements hook_civicrm_config().
*
......@@ -19,14 +96,14 @@ function _stripe_civix_civicrm_config(&$config = NULL) {
$extRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$extDir = $extRoot . 'templates';
if ( is_array( $template->template_dir ) ) {
array_unshift( $template->template_dir, $extDir );
if (is_array($template->template_dir)) {
array_unshift($template->template_dir, $extDir);
}
else {
$template->template_dir = array( $extDir, $template->template_dir );
$template->template_dir = array($extDir, $template->template_dir);
}
$include_path = $extRoot . PATH_SEPARATOR . get_include_path( );
$include_path = $extRoot . PATH_SEPARATOR . get_include_path();
set_include_path($include_path);
}
......@@ -55,6 +132,20 @@ function _stripe_civix_civicrm_install() {
}
}
/**
* Implements hook_civicrm_postInstall().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_postInstall
*/