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 { ...@@ -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); $parsed_url['query'] . "&_qf_Main_display=1&qfKey={$qfKey}", FALSE, NULL, FALSE);
} }
// Include Stripe library then set plugin info and API credentials. // Set plugin info and API credentials.
require_once('stripe-php/init.php');
\Stripe\Stripe::setAppInfo('CiviCRM', CRM_Utils_System::version(), CRM_Utils_System::baseURL()); \Stripe\Stripe::setAppInfo('CiviCRM', CRM_Utils_System::version(), CRM_Utils_System::baseURL());
\Stripe\Stripe::setApiKey($this->_paymentProcessor['user_name']); \Stripe\Stripe::setApiKey($this->_paymentProcessor['user_name']);
......
...@@ -111,7 +111,6 @@ class CRM_Stripe_Page_Webhook extends CRM_Core_Page { ...@@ -111,7 +111,6 @@ class CRM_Stripe_Page_Webhook extends CRM_Core_Page {
CRM_Utils_System::civiExit(); 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::setAppInfo('CiviCRM', CRM_Utils_System::version(), CRM_Utils_System::baseURL());
\Stripe\Stripe::setApiKey($stripe_key); \Stripe\Stripe::setApiKey($stripe_key);
......
<?php <?php
require_once('packages/stripe-php/init.php');
/** /**
* Collection of upgrade steps. * Collection of upgrade steps.
* DO NOT USE a naming scheme other than upgrade_N, where N is an integer. * 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 @@ ...@@ -5,6 +5,7 @@
<description>Stripe Payment Processor</description> <description>Stripe Payment Processor</description>
<urls> <urls>
<url desc="Main Extension Page">http://drastikbydesign.com</url> <url desc="Main Extension Page">http://drastikbydesign.com</url>
<url desc="Support">https://www.mjwconsult.co.uk</url>
</urls> </urls>
<license>AGPL</license> <license>AGPL</license>
<maintainer> <maintainer>
......
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
$(".messages.crm-error.stripe-message:first").remove(); $(".messages.crm-error.stripe-message:first").remove();
} }
$form.prepend('<div class="messages crm-error stripe-message">' $form.prepend('<div class="messages crm-error stripe-message">'
+ '<strong>Payment Error Response:</strong>' + '<strong>Payment Error Response:</strong>'
+ '<ul id="errorList">' + '<ul id="errorList">'
+ '<li>Error: ' + response.error.message + '</li>' + '<li>Error: ' + response.error.message + '</li>'
+ '</ul>' + '</ul>'
+ '</div>'); + '</div>');
$submit.removeAttr('disabled').attr('value', buttonText); $submit.removeAttr('disabled').attr('value', buttonText);
...@@ -40,9 +40,7 @@ ...@@ -40,9 +40,7 @@
// Prepare the form. // Prepare the form.
$(document).ready(function() { $(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. // Check for form marked as a stripe-payment-form by the server.
if (!($('form.stripe-payment-form').length)) { if (!($('form.stripe-payment-form').length)) {
...@@ -55,7 +53,7 @@ ...@@ -55,7 +53,7 @@
$('#crm-container > form').addClass('stripe-payment-form'); $('#crm-container > form').addClass('stripe-payment-form');
} }
} }
$form = $('form.stripe-payment-form'); $form = $('form.stripe-payment-form');
if (isWebform) { if (isWebform) {
$submit = $form.find('.button-primary'); $submit = $form.find('.button-primary');
...@@ -183,7 +181,7 @@ ...@@ -183,7 +181,7 @@
} }
} }
else { else {
debugging('debug: qlmvy (Stripe is the only payprocessor here)'); debugging('debug: qlmvy (Stripe is the only payprocessor here)');
} }
// Handle reuse of existing token // Handle reuse of existing token
...@@ -229,7 +227,7 @@ ...@@ -229,7 +227,7 @@
}(cj, CRM)); }(cj, CRM));
function debugging (errorCode) { function debugging (errorCode) {
// Uncomment the following to debug unexpected returns. // Uncomment the following to debug unexpected returns.
// console.log(errorCode); // 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()