Skip to content

Commit

Permalink
Merge pull request #4 from academe/PaymentPage
Browse files Browse the repository at this point in the history
Payment Page payment type support
  • Loading branch information
judgej authored Jan 12, 2018
2 parents 6e5db5f + f9f95ba commit afceda8
Show file tree
Hide file tree
Showing 9 changed files with 645 additions and 14 deletions.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Table of Contents
* [Giropay Sender Details](#giropay-sender-details)
* [Giropay ID (age verification)](#giropay-id-age-verification)
* [Paydirekt Payment Type](#paydirekt-payment-type)
* [Payment Page Payment Type](#payment-page-payment-type)
* [Payment Page Projects List](#payment-page-projects-list)
* [Cancel Url](#cancel-url)

# Authentication

Expand Down Expand Up @@ -552,3 +555,53 @@ treated as the same amount):
* Float 1.23 => 123

Further documentation and examples will follow.

# Payment Page Payment Type

This payment type offers the customer all payment methods available from the
merchant rather than displaying them seperately. The payment page allows the
customer to select the payment method they wish to use and then the selected
payment is initialized accordingly.

## Payment Page Projects List

This method returns a list of possible GiroCockpit projects. The list contains the following elements:

* Project Id
* Project Name
* Paymethod Number (see [Payment methods](http://api.girocheckout.de/en:girocheckout:paypage:start#payment_methods))
* Mode (_TEST_ or _LIVE_)

```php
$gateway->setPaymentType(Gateway::PAYMENT_TYPE_PAYMENTPAGE);

$request = $gateway->getProjects();

$response = $request->send();

if ($response->isSuccessful()) {
$projects = $response->getProjects();

var_dump($projects);
}

// array(5) {
// [0]=>
// array(4) {
// ["id"]=>
// string(5) "37570"
// ["name"]=>
// string(11) "Giropay One"
// ["paymethod"]=>
// string(1) "1"
// ["mode"]=>
// string(4) "TEST"
// }
// ...
// }

```

## Cancel Url

The Payment Page `cancelUrl` differs to the rest of the payment types as it does not return the transaction cancelled details. Therefore, you must **not** call `completeAuthorise` when returning to the merchant site.
10 changes: 10 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Gateway extends AbstractGateway
const PAYMENT_TYPE_GIROPAY = 'Giropay';
const PAYMENT_TYPE_GIROPAY_ID = 'Giropay-ID';
const PAYMENT_TYPE_PAYDIREKT = 'Paydirekt';
const PAYMENT_TYPE_PAYMENTPAGE = 'PaymentPage';

const PAYMENT_TYPE_MAESTRO = 'Maestro';
const PAYMENT_TYPE_IDEAL = 'iDEAL';
Expand Down Expand Up @@ -301,6 +302,15 @@ public function getIssuers(array $parameters = [])
return $this->createRequest(Message\GetIssuersRequest::class, $parameters);
}

/**
* @param array $parameters
* @return Message\GetProjectsRequest
*/
public function getProjects(array $parameters = [])
{
return $this->createRequest(Message\GetProjectsRequest::class, $parameters);
}

/**
* @param array $parameters
* @return Message\GetSenderRequest
Expand Down
31 changes: 30 additions & 1 deletion src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ abstract class AbstractRequest extends OmnipayAbstractRequest
*/
const PURPOSE_LENGTH = 27;

/**
* @var int Maximum length of the `purpose` field on PaymentPage.
*/
const PURPOSE_LENGTH_PAYMENTAGE = 20;

/**
* @var string Request transaction types.
*/
Expand Down Expand Up @@ -496,6 +501,27 @@ public function isPaydirekt()
return $this->getPaymentType() === Gateway::PAYMENT_TYPE_PAYDIREKT;
}

/**
* @return bool true if processing a paydirekt transaction.
*/
public function isPaymentPage()
{
return $this->getPaymentType() === Gateway::PAYMENT_TYPE_PAYMENTPAGE;
}

/**
* If not set at all, then default it to false
* @return bool The value of freeAmount as bool.
*/
public function hasFreeAmount()
{
if ($this->getFreeAmount() == 1) {
return true;
} elseif ($this->getFreeAmount() == 0 || null) {
return false;
}
}

/**
* Check whether this message supports the payment type chosen.
*
Expand All @@ -516,7 +542,10 @@ public function validatePaymentType()
));
}

if (! in_array($paymentType, $this->supportedPaymentTypes)) {
if (
$this->supportedPaymentTypes !== []
&& ! in_array($paymentType, $this->supportedPaymentTypes)
) {
throw new InvalidRequestException(sprintf(
'This message does not support payment type "%s"; payment types supported: %s',
$paymentType,
Expand Down
Loading

0 comments on commit afceda8

Please sign in to comment.