Skip to content

Commit

Permalink
Merge 03d64dd into 0bafec3
Browse files Browse the repository at this point in the history
  • Loading branch information
dara committed Jan 8, 2019
2 parents 0bafec3 + 03d64dd commit 364c7e8
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ _TBD_
- [x] Added new property to `PaymentCardAuthorization`: `redirectUrl`
- [x] Added new links to `PaymentCard`: `approvalUrl`, `authTransaction`
- [x] Added new property to `Subscription`: `recentInvoiceId`
- [x] Added POST to `Transaction`

### Changed
- [x] **Upgraded minimum PHP version to 7.1**
Expand Down
165 changes: 133 additions & 32 deletions src/Entities/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,24 @@
/**
* Class Transaction
*
*
* ```json
* {
* "id"
* "createdTime"
* "type"
* "result"
* "amount"
* "currency"
* "parentTransaction"
* "rebillNumber"
* "processorAccount"
* "processorResponse"
* "website"
* "customer"
* "paymentCard"
* "payment"
* }
* ```
*
* @todo Check if `getProcessorAccountId` is a ID or name
*
*/
final class Transaction extends Entity
{
public const TYPE_AUTHORIZE = 'authorize';

public const TYPE_SALE = 'sale';

public const TYPE_CREDIT = 'credit';

public static function types()
{
return [
self::TYPE_AUTHORIZE,
self::TYPE_SALE,
self::TYPE_CREDIT,
];
}

/**
* @return string
*/
Expand All @@ -49,6 +42,16 @@ public function getAmount()
return $this->getAttribute('amount');
}

/**
* @param $value
*
* @return Transaction
*/
public function setAmount($value)
{
return $this->setAttribute('amount', $value);
}

/**
* @return string
*/
Expand All @@ -57,6 +60,16 @@ public function getCurrency()
return $this->getAttribute('currency');
}

/**
* @param $value
*
* @return Transaction
*/
public function setCurrency($value)
{
return $this->setAttribute('currency', $value);
}

/**
* @return string
*/
Expand All @@ -73,6 +86,16 @@ public function getType()
return $this->getAttribute('type');
}

/**
* @param $value
*
* @return Transaction
*/
public function setType($value)
{
return $this->setAttribute('type', $value);
}

/**
* @return string
*/
Expand Down Expand Up @@ -100,33 +123,37 @@ public function getRebillNumber()
/**
* @return string
*/
public function getProcessorAccountId()
public function getWebsiteId()
{
return $this->getAttribute('processorAccount');
return $this->getAttribute('websiteId');
}

/**
* @return string
* @param $value
*
* @return Transaction
*/
public function getProcessorResponse()
public function setWebsiteId($value)
{
return $this->getAttribute('processorResponse');
return $this->setAttribute('websiteId', $value);
}

/**
* @return string
*/
public function getWebsiteId()
public function getCustomerId()
{
return $this->getAttribute('website');
return $this->getAttribute('customerId');
}

/**
* @return string
* @param $value
*
* @return Transaction
*/
public function getCustomerId()
public function setCustomerId($value)
{
return $this->getAttribute('customerId');
return $this->setAttribute('customerId', $value);
}

/**
Expand Down Expand Up @@ -193,6 +220,16 @@ public function getInvoiceIds()
return $this->getAttribute('invoiceIds');
}

/**
* @param $value
*
* @return Transaction
*/
public function setInvoiceIds($value)
{
return $this->setAttribute('invoiceIds', $value);
}

/**
* @return string
*/
Expand Down Expand Up @@ -249,6 +286,16 @@ public function getMethod()
return $this->getAttribute('method');
}

/**
* @param $value
*
* @return Transaction
*/
public function setMethod($value)
{
return $this->setAttribute('method', $value);
}

/**
* @return string
*/
Expand Down Expand Up @@ -289,6 +336,16 @@ public function getBillingAddress()
return $this->getAttribute('billingAddress');
}

/**
* @param $value
*
* @return Transaction
*/
public function setBillingAddress($value)
{
return $this->setAttribute('billingAddress', $value);
}

/**
* @return RiskMetadata
*/
Expand Down Expand Up @@ -331,6 +388,50 @@ public function getRedirectUrls()
return $this->getAttribute('redirectUrls');
}

/**
* @return string
*/
public function getRedirectUrl()
{
return $this->getAttribute('redirectUrl');
}

/**
* @param $value
*
* @return Transaction
*/
public function setRedirectUrl($value)
{
return $this->setAttribute('redirectUrl', $value);
}

/**
* @return string
*/
public function getNotificationUrl()
{
return $this->getAttribute('notificationUrl');
}

/**
* @param $value
*
* @return Transaction
*/
public function setNotificationUrl($value)
{
return $this->setAttribute('notificationUrl', $value);
}

/**
* @return string
*/
public function getApprovalUrl()
{
return $this->getLink('approvalUrl');
}

/**
* @return null|Customer
*/
Expand Down
15 changes: 15 additions & 0 deletions src/Services/TransactionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,19 @@ public function refund($transactionId, $amount)
['transactionId' => $transactionId]
);
}

/**
* @param array|JsonSerializable|Transaction $data
*
* @throws UnprocessableEntityException The input data does not valid
*
* @return Transaction
*/
public function create($data)
{
return $this->client()->post(
$data,
'transactions'
);
}
}
6 changes: 5 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ protected function getFakeValue($attribute, $class)
case 'cavv':
case 'xid':
case 'senderName':
case 'redirectUrl':
case 'request':
case 'response':
case 'acquirerReferenceNumber':
return $faker->word;
case 'redirectUrl':
case 'notificationUrl':
return $faker->url;
case 'organization':
case 'company':
return $faker->company;
Expand Down Expand Up @@ -317,6 +319,8 @@ protected function getFakeValue($attribute, $class)
return $faker->randomElement(Entities\ApiKey::datetimeFormats());
case Entities\Dispute::class:
return $faker->randomElement(Entities\Dispute::allowedTypes());
case Entities\Transaction::class:
return $faker->randomElement(Entities\Transaction::types());
default:
throw new InvalidArgumentException(
sprintf('Cannot generate fake value for "%s :: %s"', $class, $attribute)
Expand Down

0 comments on commit 364c7e8

Please sign in to comment.