Skip to content

Commit

Permalink
Merge branch 'pr10'
Browse files Browse the repository at this point in the history
  • Loading branch information
judgej committed Jul 12, 2018
2 parents 6febe4b + 8564960 commit 92b5df7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
46 changes: 42 additions & 4 deletions src/Message/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class AuthorizeRequest extends AbstractRequest
Gateway::PAYMENT_TYPE_CREDIT_CARD,
Gateway::PAYMENT_TYPE_DIRECTDEBIT,
Gateway::PAYMENT_TYPE_MAESTRO,
Gateway::PAYMENT_TYPE_GIROPAY,
Gateway::PAYMENT_TYPE_EPS,
Gateway::PAYMENT_TYPE_PAYDIREKT,
Gateway::PAYMENT_TYPE_PAYMENTPAGE,
Expand Down Expand Up @@ -129,7 +128,9 @@ public function getPaydirektData($data = [])
$data['customerId'] = $customerId;
}

// TODO: shippingAmount - can we get this from the cart? Probably not.
if ($shippingAmount = $this->getShippingAmount()) {
$data['shippingAmount'] = $shippingAmount;
}

if ($card = $this->getCard()) {
if ($shippingFirstName = $card->getShippingFirstName()) {
Expand Down Expand Up @@ -181,8 +182,9 @@ public function getPaydirektData($data = [])
}
}

// TODO: orderAmount probably from the cart, not the card.
// This is the total amount minus any shipping.
if ($orderAmount = $this->getOrderAmount()) {
$data['orderAmount'] = $orderAmount;
}

// TODO: validate this is set (this is mandatory).
$orderId = $this->getOrderId();
Expand Down Expand Up @@ -1023,6 +1025,42 @@ public function setOrderId($value)
return $this->setParameter('orderId', $value);
}

/**
* @return int|float The shipping amount
*/
public function getShippingAmount()
{
return $this->getParameter('shippingAmount');
}

/**
* @param int|float $shippingAmount
*
* @return $this
*/
public function setShippingAmount($shippingAmount)
{
return $this->setParameter('shippingAmount', $shippingAmount);
}

/**
* @return int|float The order amount
*/
public function getOrderAmount()
{
return $this->getParameter('orderAmount');
}

/**
* @param int|float $orderAmount
*
* @return $this
*/
public function setOrderAmount($orderAmount)
{
return $this->setParameter('orderAmount', $orderAmount);
}

/**
* @return string For Paydirekt
*/
Expand Down
18 changes: 17 additions & 1 deletion tests/Message/AuthorizeRequestPaydirektTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public function setUp()
'card' => $card,
'items' => $items,
'orderId' => 'ORD-123',
'shippingAmount' => 1234,
'orderAmount' => 5678,
]);
}

Expand Down Expand Up @@ -124,7 +126,7 @@ public function testHash()

// This hash will change if the initializartion data changes.
$data = $this->request->getData();
$this->assertSame('c4c1c3581f266e3e0cb17b832685fa4c', $data['hash']);
$this->assertSame('1b1c0deca31a2a97c167bd7f9a116564', $data['hash']);

$data = [
'merchantId' => '1234567',
Expand Down Expand Up @@ -198,4 +200,18 @@ public function testCurrencyDerived()
$this->request->setCurrency('GBP');
$this->assertSame('GBP', $this->request->getCurrencyFallback());
}

/**
* See https://github.com/academe/Omnipay-GiroCheckout/pull/10
*/
public function testOrderAmounts()
{
//$this->request->setShippingAmount(1234);
//$this->request->setOrderAmount(5678);

$data = $this->request->getData();

$this->assertSame(1234, $data['shippingAmount']);
$this->assertSame(5678, $data['orderAmount']);
}
}
2 changes: 1 addition & 1 deletion tests/Message/PurchaseRequestPaydirektTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testHash()

// This hash will change if the initializartion data changes.
$data = $this->request->getData();
$this->assertSame('239da494f2e276bb2c91b5a8aef79f42', $data['hash']);
$this->assertSame('152d3e9f968ffa14436fa09c8e97e67a', $data['hash']);
}

}

0 comments on commit 92b5df7

Please sign in to comment.