Skip to content

Commit 730b7f5

Browse files
committed
Various tidy-up and TODOs comleted. DPM tests still needed.
1 parent f1b1e3e commit 730b7f5

File tree

6 files changed

+49
-57
lines changed

6 files changed

+49
-57
lines changed

src/Message/DPMAuthorizeRequest.php

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,25 @@ public function getData()
1616
{
1717
$data = parent::getData();
1818

19-
// If x_show_form is swet, then the form will be displayed on the Authorize.Net
20-
// gateway, which acts a bit like the SIM gateway. The documentation does NOT
21-
// make this clear.
22-
// TODO: revisit this - maybe much of what is in the DPM can be used to enhance
23-
// the SIM gateway, with very little in the DPM messages.
19+
// If x_show_form is set, then the form will be displayed on the Authorize.Net
20+
// gateway, in a similar way to the SIM gateway. The DPM documentation does NOT
21+
// make this clear at all.
22+
// Since x_show_form is set in the SIM gateway, make sure we unset it here.
2423

25-
//$data['x_show_form'] = 'PAYMENT_FORM';
2624
unset($data['x_show_form']);
2725

28-
// Support multiple currencies.
29-
// CHECKME: should this be back-ported to SIMAuthorizeRequest and AIMAuthorizeRequest?
26+
// The card details are optional.
27+
// They will most likely only be used for development and testing.
28+
// The card fields are still needed in the direct-post form regardless.
3029

31-
if ($this->getCurrency()) {
32-
$data['x_currency_code'] = $this->getCurrency();
33-
}
34-
35-
// CHECKME: x_recurring_billing is (ambiguously) listed as mandatory in the DPM docs.
36-
37-
// The customer ID is optional.
38-
if ($this->getCustomerId()) {
39-
$data['x_cust_id'] = $this->getCustomerId();
40-
}
41-
42-
// The card details at this point are optional.
4330
if ($this->getCard()) {
4431
$data['x_card_num'] = $this->getCard()->getNumber();
4532
$data['x_exp_date'] = $this->getCard()->getExpiryDate('my');
4633
$data['x_card_code'] = $this->getCard()->getCvv();
34+
} else {
35+
$data['x_card_num'] = '';
36+
$data['x_exp_date'] = '';
37+
$data['x_card_code'] = '';
4738
}
4839

4940
return $data;

src/Message/DPMAuthorizeResponse.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class DPMAuthorizeResponse extends AbstractResponse implements RedirectResponseI
2121
protected $hiddenFields = array(
2222
'x_fp_hash',
2323
'x_amount',
24+
'x_currency_code',
2425
'x_test_request',
2526
'x_cancel_url',
2627
'x_relay_url',
@@ -64,7 +65,7 @@ public function isTransparentRedirect()
6465
// Helpers to build the form.
6566

6667
/**
67-
* The URL the form will be posted to.
68+
* The URL the form will POST to.
6869
*/
6970
public function getRedirectUrl()
7071
{
@@ -76,10 +77,12 @@ public function getRedirectMethod()
7677
return "post";
7778
}
7879

79-
// CHECKME: do we still need getHiddenData()?
80+
/**
81+
* Data that must be included as hidden fields.
82+
*/
8083
public function getRedirectData()
8184
{
82-
return $this->getHiddenData();
85+
return array_intersect_key($this->getData(), array_flip($this->hiddenFields));
8386
}
8487

8588
/**
@@ -104,18 +107,11 @@ public function unhideField($field_name)
104107
}
105108
}
106109

107-
/**
108-
* Data that must be included as hidden fields, if they are available at all.
109-
*/
110-
public function getHiddenData()
111-
{
112-
return array_intersect_key($this->getData(), array_flip($this->hiddenFields));
113-
}
114-
115110
/**
116111
* Data not in the hidden fields list.
117112
* These are not all mandatory, so you do not have to present all these
118-
* to the user.
113+
* to the user. You may also have custom fields you want to post, such
114+
* as the merchant transactionId (if not using invoiceId for this purpose).
119115
*/
120116
public function getVisibleData()
121117
{

src/Message/DPMCompleteRequest.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,37 @@ class DPMCompleteRequest extends SIMCompleteAuthorizeRequest
1111
{
1212
public function getData()
1313
{
14+
// The hash sent in the callback from the Authorize.Net gateway.
1415
$hash_posted = strtolower($this->httpRequest->request->get('x_MD5_Hash'));
16+
17+
// The transaction reference generated by the Authorize.Net gateway and sent in the callback.
1518
$posted_transaction_reference = $this->httpRequest->request->get('x_trans_id');
19+
20+
// The amount that the callback has authorized.
1621
$posted_amount = $this->httpRequest->request->get('x_amount');
22+
23+
// Calculate the hash locally, using the shared "hash secret" and login ID.
1724
$hash_calculated = $this->getDpmHash($posted_transaction_reference, $posted_amount);
1825

1926
if ($hash_posted !== $hash_calculated) {
2027
// If the hash is incorrect, then we can't trust the source nor anything sent.
21-
// Throwing exceptions here is a *really* bad idea. We are trying to get the data,
28+
// Throwing exceptions here is probably a bad idea. We are trying to get the data,
2229
// and if it is invalid, then we need to be able to log that data for analysis.
2330
// Except we can't, baceuse the exception means we can't get to the data.
31+
// For now, this is consistent with other OmniPay gateway drivers.
2432

2533
throw new InvalidRequestException('Incorrect hash');
2634
}
2735

2836
// The hashes have passed, but the amount should also be validated against the
2937
// amount in the stored and retrieved transaction. If the application has the
3038
// ability to retrieve the transaction (using the transaction_id sent as a custom
31-
// form field, or perhaps as a GET parameter on the callback URL) then it will
32-
// be checked here.
39+
// form field, or perhaps in an otherwise unused field such as x_invoice_id.
3340

3441
$amount = $this->getAmount();
3542

3643
if (isset($amount) && $amount != $posted_amount) {
37-
// The amounts don't match up. Someone may have been playing with the
44+
// The amounts don't match. Someone may have been playing with the
3845
// transaction references.
3946

4047
throw new InvalidRequestException('Incorrect amount');
@@ -45,10 +52,8 @@ public function getData()
4552

4653
/**
4754
* This hash confirms the ransaction has come from the Authorize.Net gateway.
48-
* It basically tests the shared hash secret is correct, but mixes in other details
49-
* that will change for each transaction so the hash will be unique for each transaction.
50-
* The hash secret and login ID are known to the merchent site, and the amount and transaction
51-
* reference (x_amount and x_trans_id) are sent by the gatewa.
55+
* It confirms the sender knows ther shared hash secret and that the amount and
56+
* transaction reference has not been changed in transit.
5257
*/
5358
public function getDpmHash($transaction_reference, $amount)
5459
{

src/Message/DPMCompleteResponse.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
* Authorize.Net DPM Complete Authorize Response
1010
* This is the result of handling the callback.
1111
* The result will always be a HTML redirect snippet. This gets
12-
* returned to the gateway, displayed in the user's browser, and a GET
13-
* redirect is performed using JavaScript and meta refresh (belt and braces).
12+
* returned to the gateway, displayed in the user's browser, and a
13+
* redirect is performed using JavaScript and meta refresh (for backup).
1414
* We may want to return to the success page, the failed page or the retry
15-
* page (so the user can correct the form).
15+
* page (so the user can correct the form to try again).
1616
*/
1717
class DPMCompleteResponse extends SIMCompleteAuthorizeResponse implements RedirectResponseInterface
1818
{
@@ -35,11 +35,6 @@ public function isError()
3535
return isset($this->data['x_response_code']) && static::RESPONSE_CODE_ERROR === $this->data['x_response_code'];
3636
}
3737

38-
public function getMessage()
39-
{
40-
return parent::getReasonCode() . '|' . parent::getMessage();
41-
}
42-
4338
/**
4439
* We are in the callback, and we MUST return a HTML fragment to do a redirect.
4540
* All headers we may return are discarded by the gateway, so we cannot use
@@ -51,11 +46,10 @@ public function isRedirect()
5146
}
5247

5348
/**
54-
* We default here to POST because the default redirect mechanism
55-
* in Omnipay Common only generates a HTML snippet for POST and not
56-
* GET.
57-
* TODO: We could fix that here so both GET and POST can be supported.
58-
* Our fix should also include the "form data" with the URL.
49+
* We set POST because the default redirect mechanism in Omnipay Common only
50+
* generates a HTML snippet for POST and not for the GET method.
51+
* The redirect method is actually "HTML", where a HTML page is supplied
52+
* to do a redirect using any method it likes.
5953
*/
6054
public function getRedirectMethod()
6155
{
@@ -66,7 +60,7 @@ public function getRedirectMethod()
6660
* We probably do not require any redirect data, if the incomplete transaction
6761
* is still in the user's session and we can inspect the results from the saved
6862
* transaction in the database. We cannot send the result through the redirect
69-
* unless it is hashed in some way so the authorisation result cannot be faked.
63+
* unless it is hashed so the authorisation result cannot be faked.
7064
*/
7165
public function getRedirectData()
7266
{
@@ -75,9 +69,6 @@ public function getRedirectData()
7569

7670
/**
7771
* The cancel URL is never handled here - that is a direct link from the gateway.
78-
* The best approach is to have just one redirect URL, and once there, check the
79-
* result of the authorisation in the database (assuming it has been saved in the
80-
* callback) and take action from there.
8172
*/
8273
public function getRedirectUrl()
8374
{

src/Message/SIMAuthorizeRequest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@ public function getData()
2121
$data['x_delim_data'] = 'FALSE';
2222
$data['x_show_form'] = 'PAYMENT_FORM';
2323
$data['x_relay_response'] = 'TRUE';
24+
2425
// The returnUrl MUST be set in Authorize.net admin panel as a
2526
// "Response/Receipt URLs" URL, but not necessarily the default.
2627
$data['x_relay_url'] = $this->getReturnUrl();
2728
$data['x_cancel_url'] = $this->getCancelUrl();
29+
2830
if ($this->getCustomerId() !== null) {
2931
$data['x_cust_id'] = $this->getCustomerId();
3032
}
3133

34+
if ($this->getCurrency() !== null) {
35+
$data['x_currency_code'] = $this->getCurrency();
36+
}
37+
3238
if ($this->getTestMode()) {
3339
$data['x_test_request'] = 'TRUE';
3440
}

src/Message/SIMCompleteAuthorizeRequest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public function getData()
1818
return $this->httpRequest->request->all();
1919
}
2020

21+
/**
22+
* CHECKME: DPM uses the transactionReference in the hash, not the transactionID.
23+
*/
2124
public function getHash()
2225
{
2326
return md5($this->getHashSecret().$this->getApiLoginId().$this->getTransactionId().$this->getAmount());

0 commit comments

Comments
 (0)