Skip to content
Snippets Groups Projects
Commit d3f6c83d authored by mattwire's avatar mattwire Committed by mattwire
Browse files

Update webhook version

parent 509e3f8d
Branches
Tags
No related merge requests found
......@@ -12,7 +12,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
*
* @var string
*/
const API_VERSION = '2019-02-19';
const API_VERSION = '2019-05-16';
/**
* Mode of operation: live or test.
......
......@@ -4,7 +4,7 @@ use CRM_Stripe_ExtensionUtil as E;
class CRM_Stripe_Webhook {
use CRM_Stripe_Webhook_Trait;
use CRM_Stripe_WebhookTrait;
/**
* Checks whether the payment processors have a correctly configured
......@@ -20,7 +20,7 @@ class CRM_Stripe_Webhook {
]);
foreach ($result['values'] as $paymentProcessor) {
$webhook_path = self::getWebhookPath(TRUE, $paymentProcessor['id']);
$webhook_path = self::getWebhookPath($paymentProcessor['id']);
\Stripe::setApiKey(CRM_Core_Payment_Stripe::getSecretKey($paymentProcessor));
try {
......@@ -88,7 +88,7 @@ class CRM_Stripe_Webhook {
$params = [
'enabled_events' => self::getDefaultEnabledEvents(),
'url' => self::getWebhookPath(TRUE, $paymentProcessorId),
'url' => self::getWebhookPath($paymentProcessorId),
'api_version' => CRM_Core_Payment_Stripe::getApiVersion(),
'connect' => FALSE,
];
......
<?php
/**
* https://civicrm.org/licensing
*/
trait CRM_Stripe_Webhook_Trait {
trait CRM_Stripe_WebhookTrait {
/**********************
* MJW_Webhook_Trait: 20190602
* MJW_Webhook_Trait: 20190707
*********************/
/**
......@@ -13,34 +16,12 @@ trait CRM_Stripe_Webhook_Trait {
/**
* Get the path of the webhook depending on the UF (eg Drupal, Joomla, Wordpress)
*
* @param bool $includeBaseUrl
* @param string $pp_id
* @param string $paymentProcessorId
*
* @return string
*/
public static function getWebhookPath($includeBaseUrl = TRUE, $paymentProcessorId = 'NN') {
// Assuming frontend URL because that's how the function behaved before.
// @fixme this doesn't return the right webhook path on Wordpress (often includes an extra path between .com and ? eg. abc.com/xxx/?page=CiviCRM
// We can't use CRM_Utils_System::url('civicrm/payment/ipn/' . $paymentProcessorId, NULL, $includeBaseUrl, NULL, FALSE, TRUE);
// because it returns the query string urlencoded and the base URL non urlencoded so we can't use to match existing webhook URLs
$UFWebhookPaths = [
"Drupal" => "civicrm/payment/ipn/{$paymentProcessorId}",
"Joomla" => "?option=com_civicrm&task=civicrm/payment/ipn/{$paymentProcessorId}",
"WordPress" => "?page=CiviCRM&q=civicrm/payment/ipn/{$paymentProcessorId}"
];
$basePage = '';
$config = CRM_Core_Config::singleton();
if (!empty($config->wpBasePage) && $config->userFramework == 'WordPress') {
// Add in the wordpress base page to the URL.
$basePage = (substr($config->wpBasePage, -1) == '/') ? $config->wpBasePage : "$config->wpBasePage/";
}
// Use Drupal path as default if the UF isn't in the map above
$UFWebhookPath = (array_key_exists(CIVICRM_UF, $UFWebhookPaths)) ? $UFWebhookPaths[CIVICRM_UF] : $UFWebhookPaths['Drupal'];
if ($includeBaseUrl) {
return CRM_Utils_System::baseURL() . $basePage . $UFWebhookPath;
}
public static function getWebhookPath($paymentProcessorId) {
$UFWebhookPath = CRM_Utils_System::url('civicrm/payment/ipn/' . $paymentProcessorId, NULL, TRUE, NULL, FALSE, TRUE);
return $UFWebhookPath;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment