Documentation

CRM_Core_Payment_PayPalProIPN extends CRM_Core_Payment_BaseIPN
in package

Class CRM_Core_Payment_BaseIPN.

Tags
copyright

CiviCRM LLC https://civicrm.org/licensing

Table of Contents

Properties

$_now  : mixed
$_component  : string
Component.
$_inputParameters  : array<string|int, mixed>
Input parameters from payment processor. Store these so that the code does not need to keep retrieving from the http request
$_invoiceData  : array<string|int, mixed>
Store for the variables from the invoice string.
$_isFirstOrLastRecurringPayment  : bool
Only used by AuthorizeNetIPN.
$_isPaymentExpress  : bool
Is this a payment express transaction.
$_isRecurring  : bool
Only used by AuthorizeNetIPN.
$contributionID  : int
Contribution ID.
$contributionObject  : CRM_Contribute_BAO_Contribution
Contribution object.
$contributionRecurID  : int|null
Recurring contribution ID.
$contributionRecurObject  : CRM_Contribute_BAO_ContributionRecur
Recurring contribution object.

Methods

__construct()  : mixed
Constructor function.
cancelled()  : bool
Process cancelled payment outcome.
completeTransaction()  : mixed
failed()  : bool
Set contribution to failed.
getBillingID()  : bool
getContributionRecurID()  : int|null
Get the recurring contribution ID, if any.
getInput()  : void
getPayPalPaymentProcessorID()  : int
Gets PaymentProcessorID for PayPal
getValue()  : mixed
get the values from the rp_invoice_id string.
handlePaymentExpress()  : void
Handle payment express IPNs.
main()  : void
This is the main function to call. It should be sufficient to instantiate the class (with the input parameters) & call this & all will be done
pending()  : bool
Handled pending contribution status.
recur()  : void
Process recurring contributions.
retrieve()  : mixed
sendMail()  : mixed
setContributionID()  : void
Set contribution ID.
setContributionRecurID()  : void
setInputParameters()  : mixed
Store input array on the class.
setInvoiceData()  : mixed
Set $this->_invoiceData from the input array
transactionExists()  : bool|void
Function check if transaction already exists.
unhandled()  : bool
Rollback unhandled outcomes.
getContactID()  : int
Get the relevant contact ID.
getContributionID()  : int
Get the relevant contribution ID.
getContributionObject()  : CRM_Contribute_BAO_Contribution
getContributionRecurObject()  : CRM_Contribute_BAO_ContributionRecur
Get the recurring contribution object.
single()  : void
cancelMembership()  : mixed
Logic to cancel a membership record when the related contribution changes to failed/cancelled.
cancelParticipant()  : mixed
Logic to cancel a participant record when the related contribution changes to failed/cancelled.
isContributionCompleted()  : bool
Is the original contribution completed.
processProfileCreated()  : void
Update a recurring contribution to in progress based on an ipn profile_create notification.

Properties

$_now

public static mixed $_now = \NULL

$_component

Component.

protected string $_component = 'contribute'

Are we dealing with an event an 'anything else' (contribute).

$_inputParameters

Input parameters from payment processor. Store these so that the code does not need to keep retrieving from the http request

protected array<string|int, mixed> $_inputParameters = []

$_invoiceData

Store for the variables from the invoice string.

protected array<string|int, mixed> $_invoiceData = []

$_isFirstOrLastRecurringPayment

Only used by AuthorizeNetIPN.

protected bool $_isFirstOrLastRecurringPayment = \FALSE

$_isPaymentExpress

Is this a payment express transaction.

protected bool $_isPaymentExpress = \FALSE

$_isRecurring

Only used by AuthorizeNetIPN.

protected bool $_isRecurring = \FALSE

$contributionID

Contribution ID.

protected int $contributionID

$contributionRecurID

Recurring contribution ID.

protected int|null $contributionRecurID

Methods

__construct()

Constructor function.

public __construct(array<string|int, mixed> $inputData) : mixed
Parameters
$inputData : array<string|int, mixed>

Contents of HTTP REQUEST.

Tags
throws
CRM_Core_Exception

cancelled()

Process cancelled payment outcome.

public cancelled(array<string|int, mixed> $objects) : bool

The intended replacement code is

Contribution::update(FALSE)->setValues([ 'cancel_date' => 'now', 'contribution_status_id:name' => 'Cancelled', ])->addWhere('id', '=', $contribution->id)->execute();

Parameters
$objects : array<string|int, mixed>
Tags
throws
CRM_Core_Exception
Return values
bool

completeTransaction()

public completeTransaction(array<string|int, mixed> $input, array<string|int, mixed> $ids, array<string|int, mixed> $objects) : mixed

Jumbled up function.

The purpose of this function is to transition a pending transaction to Completed including updating any related entities.

It has been overloaded to also add recurring transactions to the database, cloning the original transaction and updating related entities.

It is recommended to avoid calling this function directly and call the api functions:

  • contribution.completetransaction
  • contribution.repeattransaction

These functions are the focus of testing efforts and more accurately reflect the division of roles (the job of the IPN class is to determine the outcome, transaction id, invoice id & to validate the source and from there it should be possible to pass off transaction management.)

This function has been problematic for some time but there are now several tests via the api_v3_Contribution test and the Paypal & Authorize.net IPN tests so any refactoring should be done in conjunction with those.

This function needs to have the 'body' moved to the CRM_Contribute_BAO_Contribute class and to undergo refactoring to separate the complete transaction and repeat transaction functionality into separate functions with a shared function that updates related components.

Note that it is not necessary payment processor extension to implement an IPN class now. In general the code on the IPN class is better accessed through the api which de-jumbles it a bit.

e.g the payment class can have a function like (based on Omnipay extension):

public function handlePaymentNotification() { $response = $this->getValidatedOutcome(); if ($response->isSuccessful()) { try { // @todo check if it is a repeat transaction & call repeattransaction instead. civicrm_api3('contribution', 'completetransaction', array('id' => $this->transaction_id)); } catch (CRM_Core_Exception $e) { if (!stristr($e->getMessage(), 'Contribution already completed')) { $this->handleError('error', $this->transaction_id . $e->getMessage(), 'ipn_completion', 9000, 'An error may have occurred. Please check your receipt is correct'); $this->redirectOrExit('success'); } elseif ($this->transaction_id) { civicrm_api3('contribution', 'create', array('id' => $this->transaction_id, 'contribution_status_id' => 'Failed')); }

Parameters
$input : array<string|int, mixed>
$ids : array<string|int, mixed>
$objects : array<string|int, mixed>
Tags
throws
CRM_Core_Exception

failed()

Set contribution to failed.

public failed(array<string|int, mixed> $objects) : bool

use the api.

Parameters
$objects : array<string|int, mixed>
Tags
throws
CRM_Core_Exception
Return values
bool

getBillingID()

public getBillingID(array<string|int, mixed> &$ids) : bool

Get site billing ID.

Parameters
$ids : array<string|int, mixed>
Return values
bool

getContributionRecurID()

Get the recurring contribution ID, if any.

public getContributionRecurID() : int|null
Tags
throws
CRM_Core_Exception
Return values
int|null

getPayPalPaymentProcessorID()

Gets PaymentProcessorID for PayPal

public getPayPalPaymentProcessorID() : int
Return values
int

getValue()

get the values from the rp_invoice_id string.

public getValue(string $name[, bool $abort = TRUE ]) : mixed
Parameters
$name : string

E.g. i, values are stored in the string with letter codes.

$abort : bool = TRUE

Throw exception if not found

Tags
throws
CRM_Core_Exception

handlePaymentExpress()

Handle payment express IPNs.

public handlePaymentExpress() : void

For one off IPNS no actual response is required Recurring is more difficult as we have limited confirmation material lets look up invoice id in recur_contribution & rely on the unique transaction id to ensure no duplicated this may not be acceptable to all sites - e.g. if they are shipping or delivering something in return then the quasi security of the ids array might be required - although better to http://stackoverflow.com/questions/4848227/validate-that-ipn-call-is-from-paypal but let's assume knowledge on invoice id & schedule is enough for now esp for donations only contribute is handled

Tags
throws
CRM_Core_Exception

main()

This is the main function to call. It should be sufficient to instantiate the class (with the input parameters) & call this & all will be done

public main() : void
Tags
todo

the references to POST throughout this class need to be removed

pending()

Handled pending contribution status.

public pending(array<string|int, mixed> &$objects, object &$transaction) : bool
Parameters
$objects : array<string|int, mixed>
$transaction : object
Return values
bool

retrieve()

public retrieve(string $name, string $type[, bool $abort = TRUE ]) : mixed
Parameters
$name : string

Of variable to return.

$type : string

Data type.

  • String
  • Integer
$abort : bool = TRUE

Abort if empty.

Tags
throws
CRM_Core_Exception

sendMail()

public sendMail(array<string|int, mixed> $input, array<string|int, mixed> $ids, array<string|int, mixed> $objects) : mixed
Parameters
$input : array<string|int, mixed>

Incoming data from Payment processor.

$ids : array<string|int, mixed>

Related object IDs.

$objects : array<string|int, mixed>
Tags
todo

confirm this function is not being used by any payment processor outside core & remove.

Note that the compose message part has been moved to contribution In general LoadObjects is called first to get the objects but the composeMessageArray function now calls it

throws
CRM_Core_Exception

setContributionID()

Set contribution ID.

public setContributionID(int $contributionID) : void
Parameters
$contributionID : int

setContributionRecurID()

public setContributionRecurID(int|null $contributionRecurID) : void
Parameters
$contributionRecurID : int|null

setInputParameters()

Store input array on the class.

public setInputParameters(array<string|int, mixed> $parameters) : mixed
Parameters
$parameters : array<string|int, mixed>
Tags
throws
CRM_Core_Exception

setInvoiceData()

Set $this->_invoiceData from the input array

public setInvoiceData() : mixed

transactionExists()

Function check if transaction already exists.

public transactionExists(string $trxn_id) : bool|void
Parameters
$trxn_id : string
Return values
bool|void

unhandled()

Rollback unhandled outcomes.

public unhandled(array<string|int, mixed> &$objects, CRM_Core_Transaction &$transaction) : bool
Parameters
$objects : array<string|int, mixed>
$transaction : CRM_Core_Transaction
Return values
bool

getContributionID()

Get the relevant contribution ID.

protected getContributionID() : int

This is the contribution being paid or the original in the recurring series.

Tags
throws
CRM_Core_Exception
Return values
int

cancelMembership()

Logic to cancel a membership record when the related contribution changes to failed/cancelled.

private cancelMembership(CRM_Member_BAO_Membership $membership, int $membershipStatusID[, bool $onlyCancelPendingMembership = TRUE ]) : mixed
Parameters
$membership : CRM_Member_BAO_Membership
$membershipStatusID : int
$onlyCancelPendingMembership : bool = TRUE

Do we only cancel pending memberships? OR memberships in any status? (see CRM-18688)

Tags
todo

This is part of a bigger refactor for dev/core/issues/927 - "duplicate" functionality exists in CRM_Contribute_BAO_Contribution::cancel()

fixme

Historically failed() cancelled membership in any status, cancelled() cancelled only pending memberships so we retain that behaviour for now.

cancelParticipant()

Logic to cancel a participant record when the related contribution changes to failed/cancelled.

private cancelParticipant(mixed $participantID) : mixed
Parameters
$participantID : mixed
Tags
todo

This is part of a bigger refactor for dev/core/issues/927 - "duplicate" functionality exists in CRM_Contribute_BAO_Contribution::cancel()

throws
CRM_Core_Exception

isContributionCompleted()

Is the original contribution completed.

private isContributionCompleted() : bool
Tags
throws
CRM_Core_Exception
Return values
bool

processProfileCreated()

Update a recurring contribution to in progress based on an ipn profile_create notification.

private processProfileCreated() : void

recurring_payment_profile_created is called when the subscription has been authorized and confirmed by the user, but before a payment has been taken. The recurring_payment_id is POSTed to the IPN and we store it in the recurring contribution's processor_id.

Tags
throws
CRM_Core_Exception

        
On this page

Search results