Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiviCRM Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
CiviCRM Core
Commits
31c873bf
Commit
31c873bf
authored
4 years ago
by
eileen
Browse files
Options
Downloads
Patches
Plain Diff
Convert remaining Authorize.net test to use guzzle
This allows us to remove the handling for when a.net doesn't reply
parent
290207d6
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Core/Payment/AuthorizeNet.php
+1
-1
1 addition, 1 deletion
CRM/Core/Payment/AuthorizeNet.php
tests/phpunit/CRM/Core/Payment/AuthorizeNetTest.php
+48
-59
48 additions, 59 deletions
tests/phpunit/CRM/Core/Payment/AuthorizeNetTest.php
with
49 additions
and
60 deletions
CRM/Core/Payment/AuthorizeNet.php
+
1
−
1
View file @
31c873bf
...
...
@@ -245,7 +245,7 @@ class CRM_Core_Payment_AuthorizeNet extends CRM_Core_Payment {
$intervalLength
*=
12
;
$intervalUnit
=
'months'
;
}
elseif
(
$intervalUnit
==
'day'
)
{
elseif
(
$intervalUnit
==
=
'day'
)
{
$intervalUnit
=
'days'
;
}
elseif
(
$intervalUnit
==
'month'
)
{
...
...
This diff is collapsed.
Click to expand it.
tests/phpunit/CRM/Core/Payment/AuthorizeNetTest.php
+
48
−
59
View file @
31c873bf
...
...
@@ -53,7 +53,7 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
$contactId
=
$this
->
individualCreate
(
$nameParams
);
$invoiceID
=
123456
;
$amount
=
rand
(
100
,
1000
)
.
'.00'
;
$amount
=
7
;
$recur
=
$this
->
callAPISuccess
(
'ContributionRecur'
,
'create'
,
[
'contact_id'
=>
$contactId
,
...
...
@@ -72,7 +72,7 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
$contribution
=
$this
->
callAPISuccess
(
'Contribution'
,
'create'
,
[
'contact_id'
=>
$contactId
,
'financial_type_id'
=>
$this
->
_financialTypeId
,
'financial_type_id'
=>
'Donation'
,
'receive_date'
=>
date
(
'Ymd'
),
'total_amount'
=>
$amount
,
'invoice_id'
=>
$invoiceID
,
...
...
@@ -156,7 +156,7 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
// turn verifySSL off
Civi
::
settings
()
->
set
(
'verifySSL'
,
'0'
);
$this
->
doPayment
(
$params
);
$this
->
processor
->
doPayment
(
$params
);
// turn verifySSL on
Civi
::
settings
()
->
set
(
'verifySSL'
,
'0'
);
...
...
@@ -172,7 +172,7 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
$this
->
assertTrue
(
$result
,
'Failed to cancel subscription with Authorize.'
);
$requests
=
$this
->
getRequestBodies
();
$this
->
assertEquals
(
$this
->
getExpectedRequest
(
date
(
'Y-m-d'
)),
$requests
[
0
]);
$this
->
assertEquals
(
$this
->
getExpectedRequest
(
$contactId
,
date
(
'Y-m-d'
)),
$requests
[
0
]);
$header
=
$this
->
getRequestHeaders
()[
0
];
$this
->
assertEquals
([
'apitest.authorize.net'
],
$header
[
'Host'
]);
$this
->
assertEquals
([
'text/xml; charset=UTF8'
],
$header
[
'Content-Type'
]);
...
...
@@ -187,16 +187,18 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
* Create a single post dated payment as a recurring transaction.
*/
public
function
testCreateSinglePostDated
()
{
$start_date
=
date
(
'Ymd'
,
strtotime
(
"+ 1 week"
));
$this
->
createMockHandler
([
$this
->
getExpectedResponse
()]);
$this
->
setUpClientWithHistoryContainer
();
$this
->
processor
->
setGuzzleClient
(
$this
->
getGuzzleClient
());
$start_date
=
date
(
'Ymd'
,
strtotime
(
'+ 1 week'
));
$firstName
=
'John
_'
.
substr
(
sha1
(
rand
()),
0
,
7
)
;
$lastName
=
'Smith
_'
.
substr
(
sha1
(
rand
()),
0
,
7
)
;
$firstName
=
'John
'
;
$lastName
=
'Smith
'
;
$nameParams
=
[
'first_name'
=>
$firstName
,
'last_name'
=>
$lastName
];
$contactId
=
$this
->
individualCreate
(
$nameParams
);
$ids
=
[
'contribution'
=>
NULL
];
$invoiceID
=
sha1
(
rand
());
$amount
=
rand
(
100
,
1000
)
.
'.00'
;
$invoiceID
=
123456
;
$amount
=
70.23
;
$contributionRecurParams
=
[
'contact_id'
=>
$contactId
,
...
...
@@ -208,11 +210,11 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
'start_date'
=>
$start_date
,
'create_date'
=>
date
(
'Ymd'
),
'invoice_id'
=>
$invoiceID
,
'contribution_status_id'
=>
2
,
'contribution_status_id'
=>
''
,
'is_test'
=>
1
,
'payment_processor_id'
=>
$this
->
_paymentProcessorID
,
];
$recur
=
CRM_Contribute_BAO_
ContributionRecur
::
add
(
$contributionRecurParams
,
$ids
);
$recur
=
$this
->
callAPISuccess
(
'
ContributionRecur
'
,
'create'
,
$contributionRecurParams
);
$contributionParams
=
[
'contact_id'
=>
$contactId
,
...
...
@@ -221,18 +223,18 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
'total_amount'
=>
$amount
,
'invoice_id'
=>
$invoiceID
,
'currency'
=>
'USD'
,
'contribution_recur_id'
=>
$recur
->
id
,
'contribution_recur_id'
=>
$recur
[
'id'
]
,
'is_test'
=>
1
,
'contribution_status_id'
=>
2
,
];
$contribution
=
$this
->
callAPISuccess
(
'
c
ontribution'
,
'create'
,
$contributionParams
);
$contribution
=
$this
->
callAPISuccess
(
'
C
ontribution'
,
'create'
,
$contributionParams
);
$params
=
[
'qfKey'
=>
'00ed21c7ca00a1f7d555555596ef7_4454'
,
'hidden_CreditCard'
=>
1
,
'billing_first_name'
=>
$firstName
,
'billing_middle_name'
=>
""
,
'billing_middle_name'
=>
''
,
'billing_last_name'
=>
$lastName
,
'billing_street_address-5'
=>
'8 Hobbitton Road'
,
'billing_city-5'
=>
'The Shire'
,
...
...
@@ -259,7 +261,7 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
'price_set_id'
=>
''
,
'total_amount'
=>
$amount
,
'currency'
=>
'USD'
,
'source'
=>
"
Mordor
"
,
'source'
=>
'
Mordor
'
,
'soft_credit_to'
=>
''
,
'soft_contact_id'
=>
''
,
'billing_state_province-5'
=>
'IL'
,
...
...
@@ -269,24 +271,24 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
'year'
=>
2022
,
'month'
=>
10
,
'ip_address'
=>
'127.0.0.1'
,
'amount'
=>
70
,
'amount'
=>
70
.23
,
'amount_level'
=>
0
,
'currencyID'
=>
'USD'
,
'pcp_display_in_roll'
=>
""
,
'pcp_roll_nickname'
=>
""
,
'pcp_personal_note'
=>
""
,
'non_deductible_amount'
=>
""
,
'fee_amount'
=>
""
,
'net_amount'
=>
""
,
'invoice_id'
=>
""
,
'contribution_page_id'
=>
""
,
'pcp_display_in_roll'
=>
''
,
'pcp_roll_nickname'
=>
''
,
'pcp_personal_note'
=>
''
,
'non_deductible_amount'
=>
''
,
'fee_amount'
=>
''
,
'net_amount'
=>
''
,
'invoice_id'
=>
''
,
'contribution_page_id'
=>
''
,
'thankyou_date'
=>
NULL
,
'honor_contact_id'
=>
NULL
,
'invoiceID'
=>
$invoiceID
,
'first_name'
=>
$firstName
,
'middle_name'
=>
'bob'
,
'last_name'
=>
$lastName
,
'street_address'
=>
'8 Hobbiton Road'
.
uniqid
()
,
'street_address'
=>
'8 Hobbiton Road'
,
'city'
=>
'The Shire'
,
'state_province'
=>
'IL'
,
'postal_code'
=>
5010
,
...
...
@@ -295,7 +297,7 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
'email'
=>
"
{
$firstName
}
.
{
$lastName
}
@example.com"
,
'contactID'
=>
$contactId
,
'contributionID'
=>
$contribution
[
'id'
],
'contributionRecurID'
=>
$recur
->
id
,
'contributionRecurID'
=>
$recur
[
'id'
]
,
];
// if cancel-subscription has been called earlier 'subscriptionType' would be set to cancel.
...
...
@@ -303,52 +305,39 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
$smarty
=
CRM_Core_Smarty
::
singleton
();
$smarty
->
assign
(
'subscriptionType'
,
'create'
);
// turn verifySSL off
Civi
::
settings
()
->
set
(
'verifySSL'
,
'0'
);
$this
->
doPayment
(
$params
);
// turn verifySSL on
Civi
::
settings
()
->
set
(
'verifySSL'
,
'0'
);
$this
->
processor
->
doPayment
(
$params
);
// if subscription was successful, processor_id / subscription-id must not be null
$this
->
assertDBNotNull
(
'CRM_Contribute_DAO_ContributionRecur'
,
$recur
->
id
,
'processor_id'
,
$this
->
assertDBNotNull
(
'CRM_Contribute_DAO_ContributionRecur'
,
$recur
[
'id'
]
,
'processor_id'
,
'id'
,
'Failed to create subscription with Authorize.'
);
// cancel it or the transaction will be rejected by A.net if the test is re-run
$subscriptionID
=
CRM_Core_DAO
::
getFieldValue
(
'CRM_Contribute_DAO_ContributionRecur'
,
$recur
->
id
,
'processor_id'
);
$subscriptionID
=
CRM_Core_DAO
::
getFieldValue
(
'CRM_Contribute_DAO_ContributionRecur'
,
$recur
[
'id'
]
,
'processor_id'
);
$message
=
''
;
$result
=
$this
->
processor
->
cancelSubscription
(
$message
,
[
'subscriptionId'
=>
$subscriptionID
]);
$this
->
assertTrue
(
$result
,
'Failed to cancel subscription with Authorize.'
);
}
/**
* Process payment against the Authorize.net test server.
*
* Skip the test if the server is unresponsive.
*
* @param array $params
*
* @throws PHPUnit\Framework\SkippedTestError
*/
public
function
doPayment
(
$params
)
{
try
{
$this
->
processor
->
doPayment
(
$params
);
}
catch
(
Exception
$e
)
{
$this
->
assertTrue
((
strpos
(
$e
->
getMessage
(),
'E00001: Internal Error Occurred.'
)
!==
FALSE
),
'AuthorizeNet failed for unknown reason.'
.
$e
->
getMessage
());
$this
->
markTestSkipped
(
'AuthorizeNet test server is not in a good mood so we can\'t test this right now'
);
}
$response
=
$this
->
getResponseBodies
();
$this
->
assertEquals
(
$this
->
getExpectedResponse
(),
$response
[
0
],
3
);
$requests
=
$this
->
getRequestBodies
();
$this
->
assertEquals
(
$this
->
getExpectedRequest
(
$contactId
,
date
(
'Y-m-d'
,
strtotime
(
$start_date
)),
70.23
,
3
,
4007000000027
,
'2022-10'
),
$requests
[
0
]);
}
/**
* Get the content that we expect to see sent out.
*
* @param int $contactID
* @param string $startDate
*
* @param int $amount
* @param int $occurrences
* @param int $cardNumber
* @param string $cardExpiry
*
* @return string
*/
public
function
getExpectedRequest
(
$
startDate
)
{
public
function
getExpectedRequest
(
$
contactID
,
$startDate
,
$amount
=
7
,
$occurrences
=
12
,
$cardNumber
=
4444333322221111
,
$cardExpiry
=
'2025-09'
)
{
return
'<?xml version="1.0" encoding="utf-8"?>
<ARBCreateSubscriptionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
...
...
@@ -363,20 +352,20 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
<unit>months</unit>
</interval>
<startDate>'
.
$startDate
.
'</startDate>
<totalOccurrences>
12
</totalOccurrences>
<totalOccurrences>
'
.
$occurrences
.
'
</totalOccurrences>
</paymentSchedule>
<amount>
7
</amount>
<amount>
'
.
$amount
.
'
</amount>
<payment>
<creditCard>
<cardNumber>
4444333322221111
</cardNumber>
<expirationDate>
2025-09
</expirationDate>
<cardNumber>
'
.
$cardNumber
.
'
</cardNumber>
<expirationDate>
'
.
$cardExpiry
.
'
</expirationDate>
</creditCard>
</payment>
<order>
<invoiceNumber>1</invoiceNumber>
</order>
<customer>
<id>
3
</id>
<id>
'
.
$contactID
.
'
</id>
<email>John.Smith@example.com</email>
</customer>
<billTo>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment