Commit a5d86ea0 authored by mattwire's avatar mattwire
Browse files

No change - code standards on api classes

parent 4f425e86
......@@ -19,8 +19,6 @@
* Stripe.Ipn API specification
*
* @param array $spec description of fields supported by this API call
* @return void
* @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
*/
function _civicrm_api3_stripe_Ipn_spec(&$spec) {
$spec['id']['title'] = ts("CiviCRM System Log id to replay from system log.");
......@@ -34,10 +32,12 @@ function _civicrm_api3_stripe_Ipn_spec(&$spec) {
* Stripe.Ipn API
*
* @param array $params
*
* @return array API result descriptor
* @see civicrm_api3_create_success
* @see civicrm_api3_create_error
* @throws API_Exception
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @throws \Stripe\Error\Api
*/
function civicrm_api3_stripe_Ipn($params) {
$object = NULL;
......@@ -87,5 +87,4 @@ function civicrm_api3_stripe_Ipn($params) {
trigger_error("The api depends on CRM_Core_Payment_StripeIPN");
}
return civicrm_api3_create_success(array());
}
......@@ -13,10 +13,9 @@
/**
* Stripe.ListEvents API specification
*
*
* @param array $spec description of fields supported by this API call
*
* @return void
* @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
*/
function _civicrm_api3_stripe_ListEvents_spec(&$spec) {
$spec['ppid']['title'] = ts("Use the given Payment Processor ID");
......@@ -34,92 +33,92 @@ function _civicrm_api3_stripe_ListEvents_spec(&$spec) {
* Stripe.VerifyEventType
*
* @param string $eventType
* @return bolean True if valid type, false otherwise.
*
* @return boolean True if valid type, false otherwise.
*/
function civicrm_api3_stripe_VerifyEventType($eventType) {
return in_array($eventType, array(
'account.external_account.created',
'account.external_account.deleted',
'account.external_account.updated',
'application_fee.created',
'application_fee.refunded',
'application_fee.refund.updated',
'balance.available',
'bitcoin.receiver.created',
'bitcoin.receiver.filled',
'bitcoin.receiver.updated',
'bitcoin.receiver.transaction.created',
'charge.captured',
'charge.failed',
'charge.pending',
'charge.refunded',
'charge.succeeded',
'charge.updated',
'charge.dispute.closed',
'charge.dispute.created',
'charge.dispute.funds_reinstated',
'charge.dispute.funds_withdrawn',
'charge.dispute.updated',
'charge.refund.updated',
'coupon.created',
'coupon.deleted',
'coupon.updated',
'customer.created',
'customer.deleted',
'customer.updated',
'customer.discount.created',
'customer.discount.deleted',
'customer.discount.updated',
'customer.source.created',
'customer.source.deleted',
'customer.source.updated',
'customer.subscription.created',
'customer.subscription.deleted',
'customer.subscription.trial_will_end',
'customer.subscription.updated',
'invoice.created',
'invoice.payment_failed',
'invoice.payment_succeeded',
'invoice.upcoming',
'invoice.updated',
'invoiceitem.created',
'invoiceitem.deleted',
'invoiceitem.updated',
'order.created',
'order.payment_failed',
'order.payment_succeeded',
'order.updated',
'order_return.created',
'payout.canceled',
'payout.created',
'payout.failed',
'payout.paid',
'payout.updated',
'plan.created',
'plan.deleted',
'plan.updated',
'product.created',
'product.deleted',
'product.updated',
'recipient.created',
'recipient.deleted',
'recipient.updated',
'review.closed',
'review.opened',
'sku.created',
'sku.deleted',
'sku.updated',
'source.canceled',
'source.chargeable',
'source.failed',
'source.transaction.created',
'transfer.created',
'transfer.reversed',
'transfer.updated',
'ping',
)
);
return in_array($eventType, [
'account.external_account.created',
'account.external_account.deleted',
'account.external_account.updated',
'application_fee.created',
'application_fee.refunded',
'application_fee.refund.updated',
'balance.available',
'bitcoin.receiver.created',
'bitcoin.receiver.filled',
'bitcoin.receiver.updated',
'bitcoin.receiver.transaction.created',
'charge.captured',
'charge.failed',
'charge.pending',
'charge.refunded',
'charge.succeeded',
'charge.updated',
'charge.dispute.closed',
'charge.dispute.created',
'charge.dispute.funds_reinstated',
'charge.dispute.funds_withdrawn',
'charge.dispute.updated',
'charge.refund.updated',
'coupon.created',
'coupon.deleted',
'coupon.updated',
'customer.created',
'customer.deleted',
'customer.updated',
'customer.discount.created',
'customer.discount.deleted',
'customer.discount.updated',
'customer.source.created',
'customer.source.deleted',
'customer.source.updated',
'customer.subscription.created',
'customer.subscription.deleted',
'customer.subscription.trial_will_end',
'customer.subscription.updated',
'invoice.created',
'invoice.payment_failed',
'invoice.payment_succeeded',
'invoice.upcoming',
'invoice.updated',
'invoiceitem.created',
'invoiceitem.deleted',
'invoiceitem.updated',
'order.created',
'order.payment_failed',
'order.payment_succeeded',
'order.updated',
'order_return.created',
'payout.canceled',
'payout.created',
'payout.failed',
'payout.paid',
'payout.updated',
'plan.created',
'plan.deleted',
'plan.updated',
'product.created',
'product.deleted',
'product.updated',
'recipient.created',
'recipient.deleted',
'recipient.updated',
'review.closed',
'review.opened',
'sku.created',
'sku.deleted',
'sku.updated',
'source.canceled',
'source.chargeable',
'source.failed',
'source.transaction.created',
'transfer.created',
'transfer.reversed',
'transfer.updated',
'ping',
]
);
}
/**
......@@ -147,7 +146,7 @@ function civicrm_api3_stripe_ProcessParams($params) {
$starting_after = $params['starting_after'];
}
// Check to see if we should filter by type.
// Check to see if we should filter by type.
if (array_key_exists('type', $params) ) {
// Validate - since we will be appending this to an URL.
if (!civicrm_api3_stripe_VerifyEventType($params['type'])) {
......@@ -172,10 +171,11 @@ function civicrm_api3_stripe_ProcessParams($params) {
* Stripe.ListEvents API
*
* @param array $params
*
* @return array API result descriptor
* @see civicrm_api3_create_success
* @see civicrm_api3_create_error
* @throws API_Exception
* @throws \API_Exception
* @throws \CiviCRM_API3_Exception
* @throws \Stripe\Error\Api
*/
function civicrm_api3_stripe_Listevents($params) {
$parsed = civicrm_api3_stripe_ProcessParams($params);
......@@ -184,7 +184,7 @@ function civicrm_api3_stripe_Listevents($params) {
$limit = $parsed['limit'];
$starting_after = $parsed['starting_after'];
$args = array();
$args = [];
if ($type) {
$args['type'] = $type;
}
......@@ -208,15 +208,15 @@ function civicrm_api3_stripe_Listevents($params) {
}
$out = $data_list;
if ($params['output'] == 'brief') {
$out = array();
$out = [];
foreach($data_list['data'] as $data) {
$item = array(
$item = [
'id' => $data['id'],
'created' => date('Y-m-d H:i:s', $data['created']),
'livemode' => $data['livemode'],
'pending_webhooks' => $data['pending_webhooks'],
'type' => $data['type'],
);
];
if (preg_match('/invoice\.payment_/', $data['type'])) {
$item['invoice'] = $data['data']['object']->id;
$item['charge'] = $data['data']['object']->charge;
......@@ -226,13 +226,14 @@ function civicrm_api3_stripe_Listevents($params) {
// Check if this is in the contributions table.
$item['processed'] = 'no';
$results = civicrm_api3('Contribution', 'get', array('trxn_id' => $item['charge']));
$results = civicrm_api3('Contribution', 'get', ['trxn_id' => $item['charge']]);
if ($results['count'] > 0) {
$item['processed'] = 'yes';
}
else {
// Newer versions of stripe store the invoice id in trxn_id.
$results = civicrm_api3('Contribution', 'get', array('trxn_id' => $item['invoice']));
// From 6.0 we store the Stripe Invoice ID in the Contribution.trxn_id if available (ie it's a recur).
// Otherwise we continue to store the Stripe Charge ID.
$results = civicrm_api3('Contribution', 'get', ['trxn_id' => $item['invoice']]);
if ($results['count'] > 0) {
$item['processed'] = 'yes';
}
......@@ -242,7 +243,4 @@ function civicrm_api3_stripe_Listevents($params) {
}
}
return civicrm_api3_create_success($out);
}
......@@ -17,8 +17,6 @@
* Stripe.Populatelog API specification
*
* @param array $spec description of fields supported by this API call
* @return void
* @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
*/
function _civicrm_api3_stripe_Populatelog_spec(&$spec) {
$spec['ppid']['title'] = ts("The id of the payment processor.");
......@@ -28,10 +26,10 @@ function _civicrm_api3_stripe_Populatelog_spec(&$spec) {
* Stripe.Populatelog API
*
* @param array $params
*
* @return array API result descriptor
* @see civicrm_api3_create_success
* @see civicrm_api3_create_error
* @throws API_Exception
* @throws \API_Exception
* @throws \CiviCRM_API3_Exception
*/
function civicrm_api3_stripe_Populatelog($params) {
$ppid = NULL;
......@@ -41,7 +39,7 @@ function civicrm_api3_stripe_Populatelog($params) {
else {
// By default, select the live stripe processor (we expect there to be
// only one).
$query_params = array('class_name' => 'Payment_Stripe', 'is_test' => 0, 'return' => 'id');
$query_params = ['class_name' => 'Payment_Stripe', 'is_test' => 0, 'return' => 'id'];
try {
$ppid = civicrm_api3('PaymentProcessor', 'getvalue', $params);
}
......@@ -50,12 +48,12 @@ function civicrm_api3_stripe_Populatelog($params) {
}
}
$params = array('limit' => 100, 'type' => 'invoice.payment_succeeded');
$params = ['limit' => 100, 'type' => 'invoice.payment_succeeded'];
if ($ppid) {
$params['ppid'] = $ppid;
}
$items = array();
$items = [];
$last_item = NULL;
$more = TRUE;
while(1) {
......@@ -71,7 +69,7 @@ function civicrm_api3_stripe_Populatelog($params) {
$items = array_merge($items, $objects['values']['data']);
$last_item = end($objects['values']['data']);
}
$results = array();
$results = [];
foreach($items as $item) {
$id = $item->id;
// Insert into System Log if it doesn't exist.
......@@ -94,7 +92,7 @@ function civicrm_api3_stripe_Populatelog($params) {
}
function civcrm_api3_stripe_cid_for_trxn($trxn) {
$params = array('trxn_id' => $trxn, 'return' => 'contact_id');
$params = ['trxn_id' => $trxn, 'return' => 'contact_id'];
$result = civicrm_api3('Contribution', 'getvalue', $params);
return $result;
}
......@@ -13,8 +13,6 @@
* Stripe.Setuptest API specification
*
* @param array $spec description of fields supported by this API call
* @return void
* @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
*/
function _civicrm_api3_stripe_Setuptest_spec(&$spec) {
// Note: these test credentials belong to PTP and are contributed to
......@@ -28,28 +26,28 @@ function _civicrm_api3_stripe_Setuptest_spec(&$spec) {
* Stripe.Setuptest API
*
* @param array $params
*
* @return array API result descriptor
* @see civicrm_api3_create_success
* @see civicrm_api3_create_error
* @throws API_Exception
*
* @throws \CiviCRM_API3_Exception
*/
function civicrm_api3_stripe_Setuptest($params) {
$params = array(
'name' => 'Stripe',
'domain_id' => CRM_Core_Config::domainID(),
'payment_processor_type_id' => 'Stripe',
'title' => 'Stripe',
'is_active' => 1,
'is_default' => 0,
'is_test' => 1,
'is_recur' => 1,
'user_name' => $params['sk'],
'password' => $params['pk'],
'url_site' => 'https://api.stripe.com/v1',
'url_recur' => 'https://api.stripe.com/v1',
'class_name' => 'Payment_Stripe',
'billing_mode' => 1
);
$params = [
'name' => 'Stripe',
'domain_id' => CRM_Core_Config::domainID(),
'payment_processor_type_id' => 'Stripe',
'title' => 'Stripe',
'is_active' => 1,
'is_default' => 0,
'is_test' => 1,
'is_recur' => 1,
'user_name' => $params['sk'],
'password' => $params['pk'],
'url_site' => 'https://api.stripe.com/v1',
'url_recur' => 'https://api.stripe.com/v1',
'class_name' => 'Payment_Stripe',
'billing_mode' => 1
];
// First see if it already exists.
$result = civicrm_api3('PaymentProcessor', 'get', $params);
if ($result['count'] != 1) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment