Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #84 from heidelpay/develop
Browse files Browse the repository at this point in the history
release Version 1.1.3.0
  • Loading branch information
Simon Gabriel authored Jun 18, 2019
2 parents a895b3a + 364ec43 commit 876bdf0
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 55 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.1.3.0][1.1.3.0]

### Added
* Added property `paymentReference` to charge and refund transaction.

### Changed
* Adapted tests to new api behavior.

## [1.1.2.0][1.1.2.0]

### Added
Expand Down Expand Up @@ -172,3 +180,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
[1.1.0.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.0.2.0..1.1.0.0
[1.1.1.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.1.0.0..1.1.1.0
[1.1.2.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.1.1.0..1.1.2.0
[1.1.3.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.1.2.0..1.1.3.0
50 changes: 29 additions & 21 deletions src/Heidelpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Heidelpay implements HeidelpayParentInterface
const BASE_URL = 'https://api.heidelpay.com/';
const API_VERSION = 'v1';
const SDK_TYPE = 'HeidelpayPHP';
const SDK_VERSION = '1.1.2.0';
const SDK_VERSION = '1.1.3.0';

/** @var string $key */
private $key;
Expand Down Expand Up @@ -955,19 +955,20 @@ public function authorizeWithPayment(
/**
* Performs a Charge transaction and returns the resulting Charge resource.
*
* @param float $amount The amount to charge.
* @param string $currency The currency of the amount.
* @param string|BasePaymentType $paymentType The PaymentType object or the id of the PaymentType to use.
* @param string $returnUrl The URL used to return to the shop if the process requires leaving it.
* @param Customer|string|null $customer The Customer object or the id of the customer resource to reference.
* @param string|null $orderId A custom order id which can be set by the merchant.
* @param Metadata|null $metadata The Metadata object containing custom information for the payment.
* @param Basket|null $basket The Basket object corresponding to the payment.
* The Basket object will be created automatically if it does not exist
* yet (i.e. has no id).
* @param bool|null $card3ds Enables 3ds channel for credit cards if available. This parameter is
* optional and will be ignored if not applicable.
* @param string|null $invoiceId The external id of the invoice.
* @param float $amount The amount to charge.
* @param string $currency The currency of the amount.
* @param string|BasePaymentType $paymentType The PaymentType object or the id of the PaymentType to use.
* @param string $returnUrl The URL used to return to the shop if the process requires leaving it.
* @param Customer|string|null $customer The Customer object or the id of the customer resource to reference.
* @param string|null $orderId A custom order id which can be set by the merchant.
* @param Metadata|null $metadata The Metadata object containing custom information for the payment.
* @param Basket|null $basket The Basket object corresponding to the payment.
* The Basket object will be created automatically if it does not exist
* yet (i.e. has no id).
* @param bool|null $card3ds Enables 3ds channel for credit cards if available. This parameter is
* optional and will be ignored if not applicable.
* @param string|null $invoiceId The external id of the invoice.
* @param string|null $paymentReference A reference text for the payment.
*
* @return Charge The resulting object of the Charge resource.
*
Expand All @@ -984,7 +985,8 @@ public function charge(
$metadata = null,
$basket = null,
$card3ds = null,
$invoiceId = null
$invoiceId = null,
$paymentReference = null
): AbstractTransactionType {
return $this->paymentService->charge(
$amount,
Expand All @@ -996,7 +998,8 @@ public function charge(
$metadata,
$basket,
$card3ds,
$invoiceId
$invoiceId,
$paymentReference
);
}

Expand Down Expand Up @@ -1099,18 +1102,23 @@ public function cancelChargeById($paymentId, $chargeId, $amount = null): Abstrac
* Performs a Cancellation transaction and returns the resulting Cancellation object.
* Performs a full cancel if the parameter amount is null.
*
* @param Charge $charge The Charge object to create the Cancellation for.
* @param float|null $amount The amount to be canceled.
* @param Charge $charge The Charge object to create the Cancellation for.
* @param float|null $amount The amount to be canceled.
* @param string|null $reasonCode
* @param string|null $paymentReference A reference string for the payment.
*
* @return Cancellation The resulting Cancellation object.
*
* @throws HeidelpayApiException A HeidelpayApiException is thrown if there is an error returned on API-request.
* @throws RuntimeException A RuntimeException is thrown when there is a error while using the SDK.
*/
public function cancelCharge(Charge $charge, $amount = null, string $reasonCode = null): AbstractTransactionType
{
return $this->paymentService->cancelCharge($charge, $amount, $reasonCode);
public function cancelCharge(
Charge $charge,
$amount = null,
string $reasonCode = null,
string $paymentReference = null
): AbstractTransactionType {
return $this->paymentService->cancelCharge($charge, $amount, $reasonCode, $paymentReference);
}

//</editor-fold>
Expand Down
22 changes: 22 additions & 0 deletions src/Resources/TransactionTypes/Cancellation.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class Cancellation extends AbstractTransactionType
/** @var string $reasonCode */
protected $reasonCode;

/** @var string $paymentReference */
protected $paymentReference;

/**
* Authorization constructor.
*
Expand Down Expand Up @@ -96,5 +99,24 @@ public function setReasonCode($reasonCode): Cancellation
return $this;
}

/**
* @return string|null
*/
public function getPaymentReference()
{
return $this->paymentReference;
}

/**
* @param string|null $paymentReference
*
* @return Cancellation
*/
public function setPaymentReference($paymentReference): Cancellation
{
$this->paymentReference = $paymentReference;
return $this;
}

//</editor-fold>
}
29 changes: 26 additions & 3 deletions src/Resources/TransactionTypes/Charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class Charge extends AbstractTransactionType
/** @var string $descriptor */
private $descriptor;

/** @var string $paymentReference */
protected $paymentReference;

/** @var bool $card3ds */
protected $card3ds;

Expand Down Expand Up @@ -221,6 +224,25 @@ protected function setDescriptor(string $descriptor): self
return $this;
}

/**
* @return string|null
*/
public function getPaymentReference()
{
return $this->paymentReference;
}

/**
* @param string|null $paymentReference
*
* @return Charge
*/
public function setPaymentReference($paymentReference): Charge
{
$this->paymentReference = $paymentReference;
return $this;
}

/**
* @return bool|null
*/
Expand Down Expand Up @@ -259,16 +281,17 @@ protected function getResourcePath(): string
* Returns the last cancellation object if charge is already canceled.
* Creates and returns new cancellation object otherwise.
*
* @param float $amount
* @param float|null $amount
* @param string|null $reasonCode
* @param string|null $paymentReference
*
* @return Cancellation
*
* @throws HeidelpayApiException
* @throws RuntimeException
*/
public function cancel($amount = null, string $reasonCode = null): Cancellation
public function cancel($amount = null, string $reasonCode = null, string $paymentReference = null): Cancellation
{
return $this->getHeidelpayObject()->cancelCharge($this, $amount, $reasonCode);
return $this->getHeidelpayObject()->cancelCharge($this, $amount, $reasonCode, $paymentReference);
}
}
36 changes: 23 additions & 13 deletions src/Services/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,14 @@ public function authorizeWithPayment(
* @param string $returnUrl
* @param Customer|string|null $customer
* @param string|null $orderId
* @param Metadata|null $metadata The Metadata object containing custom information for the payment.
* @param Basket|null $basket The Basket object corresponding to the payment.
* The Basket object will be created automatically if it does not exist
* yet (i.e. has no id).
* @param bool|null $card3ds Enables 3ds channel for credit cards if available. This parameter is
* optional and will be ignored if not applicable.
* @param string|null $invoiceId The external id of the invoice.
* @param Metadata|null $metadata The Metadata object containing custom information for the payment.
* @param Basket|null $basket The Basket object corresponding to the payment.
* The Basket object will be created automatically if it does not exist
* yet (i.e. has no id).
* @param bool|null $card3ds Enables 3ds channel for credit cards if available. This parameter is
* optional and will be ignored if not applicable.
* @param string|null $invoiceId The external id of the invoice.
* @param string|null $paymentReference A reference text for the payment.
*
* @return Charge Resulting Charge object.
*
Expand All @@ -246,10 +247,12 @@ public function charge(
$metadata = null,
$basket = null,
$card3ds = null,
$invoiceId = null
$invoiceId = null,
$paymentReference = null
): AbstractTransactionType {
$payment = $this->createPayment($paymentType);
$charge = (new Charge($amount, $currency, $returnUrl))->setOrderId($orderId)->setInvoiceId($invoiceId);
$charge = new Charge($amount, $currency, $returnUrl);
$charge->setOrderId($orderId)->setInvoiceId($invoiceId)->setPaymentReference($paymentReference);
if ($card3ds !== null) {
$charge->setCard3ds($card3ds);
}
Expand Down Expand Up @@ -367,17 +370,24 @@ public function cancelChargeById($payment, $chargeId, $amount = null): AbstractT
* @param Charge $charge
* @param $amount
* @param string|null $reasonCode
* @param string|null $paymentReference A reference string for the payment.
*
* @return Cancellation Resulting Cancellation object.
*
* @throws HeidelpayApiException
* @throws RuntimeException
*/
public function cancelCharge(Charge $charge, $amount = null, string $reasonCode = null): AbstractTransactionType
{
public function cancelCharge(
Charge $charge,
$amount = null,
string $reasonCode = null,
string $paymentReference = null
): AbstractTransactionType {
$cancellation = new Cancellation($amount);
$cancellation->setReasonCode($reasonCode);
$cancellation->setPayment($charge->getPayment());
$cancellation
->setReasonCode($reasonCode)
->setPayment($charge->getPayment())
->setPaymentReference($paymentReference);
$charge->addCancellation($cancellation);
$this->resourceService->create($cancellation);

Expand Down
19 changes: 11 additions & 8 deletions src/Traits/CanDirectCharge.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ trait CanDirectCharge
* @param Customer|string|null $customer
* @param string|null $orderId
* @param Metadata|string|null $metadata
* @param Basket|null $basket The Basket object corresponding to the payment.
* The Basket object will be created automatically if it does not exist
* yet (i.e. has no id).
* @param bool|null $card3ds Enables 3ds channel for credit cards if available. This parameter is
* optional and will be ignored if not applicable.
* @param string|null $invoiceId The external id of the invoice.
* @param Basket|null $basket The Basket object corresponding to the payment.
* The Basket object will be created automatically if it does not exist
* yet (i.e. has no id).
* @param bool|null $card3ds Enables 3ds channel for credit cards if available. This parameter is
* optional and will be ignored if not applicable.
* @param string|null $invoiceId The external id of the invoice.
* @param string|null $paymentReference A reference text for the payment.
*
* @return Charge
*
Expand All @@ -65,7 +66,8 @@ public function charge(
$metadata = null,
$basket = null,
$card3ds = null,
$invoiceId = null
$invoiceId = null,
$paymentReference = null
): Charge {
if ($this instanceof HeidelpayParentInterface) {
return $this->getHeidelpayObject()->charge(
Expand All @@ -78,7 +80,8 @@ public function charge(
$metadata,
$basket,
$card3ds,
$invoiceId
$invoiceId,
$paymentReference
);
}

Expand Down
21 changes: 12 additions & 9 deletions src/Traits/CanDirectChargeWithCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ trait CanDirectChargeWithCustomer
* @param Customer|string $customer
* @param string|null $orderId
* @param Metadata|null $metadata
* @param Basket|null $basket The Basket object corresponding to the payment.
* The Basket object will be created automatically if it does not exist
* yet (i.e. has no id).
* @param bool|null $card3ds Enables 3ds channel for credit cards if available. This parameter is
* optional and will be ignored if not applicable.
* @param string|null $invoiceId The external id of the invoice.
* @param Basket|null $basket The Basket object corresponding to the payment.
* The Basket object will be created automatically if it does not exist
* yet (i.e. has no id).
* @param bool|null $card3ds Enables 3ds channel for credit cards if available. This parameter is
* optional and will be ignored if not applicable.
* @param string|null $invoiceId The external id of the invoice.
* @param string|null $paymentReference A reference text for the payment.
*
* @return Charge
*
* @throws RuntimeException
* @throws HeidelpayApiException
* @throws RuntimeException
*/
public function charge(
$amount,
Expand All @@ -65,7 +66,8 @@ public function charge(
$metadata = null,
$basket = null,
$card3ds = null,
$invoiceId = null
$invoiceId = null,
$paymentReference = null
): Charge {
if ($this instanceof HeidelpayParentInterface) {
return $this->getHeidelpayObject()->charge(
Expand All @@ -78,7 +80,8 @@ public function charge(
$metadata,
$basket,
$card3ds,
$invoiceId
$invoiceId,
$paymentReference
);
}

Expand Down
16 changes: 16 additions & 0 deletions test/integration/CancelAfterChargeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,20 @@ public function chargeShouldBePartlyRefundable()
$this->assertAmounts($secondPayment, 0, 90, 100, 10);
$this->assertTrue($secondPayment->isCompleted());
}

/**
* Verify payment reference can be set in cancel charge transaction aka refund.
*
* @test
*
* @throws HeidelpayApiException
* @throws RuntimeException
*/
public function cancelShouldAcceptPaymentReferenceParameter()
{
$card = $this->heidelpay->createPaymentType($this->createCardObject());
$charge = $this->heidelpay->charge(100.0000, 'EUR', $card, self::RETURN_URL, null, null, null, null, false);
$cancel = $charge->cancel(null, null, 'myPaymentReference');
$this->assertEquals('myPaymentReference', $cancel->getPaymentReference());
}
}
Loading

0 comments on commit 876bdf0

Please sign in to comment.