Skip to content

Commit

Permalink
Merge pull request #6 from io-digital/cleanup
Browse files Browse the repository at this point in the history
Minor code clean up and readme tweaks.
  • Loading branch information
garethnic authored May 13, 2020
2 parents 75e834e + e0c8c01 commit 2a103cd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
12 changes: 8 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The variables that can be used are:
- `PEACH_PAYMENTS_ENTITY_ID_RECURRING`
- `PEACH_PAYMENTS_TEST_MODE`
- `PEACH_PAYMENTS_NOTIFICATION_URL`
- `PEACH_PAYMENTS_WEBHOOK_SECRET_KEY`

### Migrations

Expand All @@ -39,6 +40,9 @@ This table can be used in conjunction with Server to Server functionality.
#### `payment_results`
This table can be used to store the results of transactions.

#### `payment_events`
This table can be used to store the event data received from webhooks.

## Usage

This package provides the ability of using Server to Server and COPYandPay.
Expand All @@ -62,8 +66,8 @@ Methods available to Server to Server:
```php
registerCard(CardBuilder $card);
registerCardDuringPayment(CardBuilder $card);
repeatedPayment(string $registrationId, int $amount, string $type = PaymentScheme::REPEATED_PAYMENT);
oneClickPayment(string $registrationId, int $amount);
repeatedPayment(PaymentCard $card, $owner, int $amount, string $type = PaymentScheme::REPEATED_PAYMENT);
oneClickPayment(PaymentCard $card, int $amount);
paymentStatus(string $paymentId);
deleteCard(string $registrationId);

Expand All @@ -78,8 +82,8 @@ prepareCheckout(int $amount);
getCheckoutRegistrationResult($checkoutId);
registerCard();
registerCardDuringPayment(int $amount);
repeatedPayment(string $registrationId, int $amount, string $type = PaymentScheme::REPEATED_PAYMENT);
paymentStatus(string $checkoutId)
repeatedPayment(PaymentCard $card, $owner, int $amount, string $type = PaymentScheme::REPEATED_PAYMENT);
paymentStatus(string $checkoutId);
```

To determine the result of a transaction with Peach Payment, you can
Expand Down
20 changes: 11 additions & 9 deletions src/Api/PaymentMethods/CopyAndPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace IoDigital\PeachPayment\Api\PaymentMethods;

use GuzzleHttp\Exception\ClientException;
use IoDigital\PeachPayment\Api\Factory\PaymentScheme;
use IoDigital\PeachPayment\Api\Response;
use IoDigital\PeachPayment\Api\Setting;
Expand Down Expand Up @@ -97,7 +98,7 @@ public function getCheckoutRegistrationResult($path, $owner)
'result' => $result,
'owner' => $owner
]);

return $result;
}

Expand All @@ -113,7 +114,8 @@ public function getCheckoutRegistrationResult($path, $owner)
* and useful card information that you can store for
* future 'one-click payment' requests.
*
* @param int $amount
* @param int $amount
* @param bool $preAuth
*
* @return mixed|\Psr\Http\Message\ResponseInterface
*/
Expand All @@ -124,7 +126,7 @@ public function registerCardDuringPayment(int $amount, $preAuth = false)
'entityId' => $this->settings->getEntityIdOnceOff(),
'amount' => Currency::paymentFriendlyNumber($amount),
'currency' => 'ZAR',
'paymentType' => $preAuth == true ? self::PREAUTHORISATION : self::DEBIT,
'paymentType' => $preAuth === true ? self::PREAUTHORISATION : self::DEBIT,
'createRegistration' => true,
],
])->getBody()->getContents();
Expand All @@ -146,9 +148,10 @@ public function registerCardDuringPayment(int $amount, $preAuth = false)
* use should use INITIAL_PAYMENT.
*
*
* @param string $registrationId
* @param int $amount
* @param string $type
* @param PaymentCard $card
* @param $owner
* @param int $amount
* @param string $type
*
* @return mixed|\Psr\Http\Message\ResponseInterface
*/
Expand Down Expand Up @@ -191,10 +194,9 @@ public function repeatedPayment(PaymentCard $card, $owner, int $amount, string $
/**
* Perform a one click payment with a stored card.
*
* @param string $registrationId
* @param int $amount
* @param PaymentCard $card
* @param int $amount
* @return mixed|\Psr\Http\Message\ResponseInterface
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function oneClickPayment(PaymentCard $card, int $amount)
{
Expand Down
25 changes: 12 additions & 13 deletions src/Api/PaymentMethods/ServerToServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use GuzzleHttp\Exception\ClientException;
use IoDigital\PeachPayment\Api\CardBuilder;
use IoDigital\PeachPayment\Api\Factory\PaymentScheme;
use IoDigital\PeachPayment\Api\Setting;
use IoDigital\PeachPayment\Api\Response;
use IoDigital\PeachPayment\Api\Setting;
use IoDigital\PeachPayment\Helpers\Currency;
use IoDigital\PeachPayment\Models\PaymentCard;

Expand All @@ -24,8 +24,9 @@ public function __construct(Setting $settings = null)
/**
* Do a standalone card registration.
*
* @param CardBuilder $card
*
* @return mixed|\Psr\Http\Message\ResponseInterface
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function registerCard(CardBuilder $card)
{
Expand Down Expand Up @@ -84,9 +85,10 @@ public function registerCardDuringPayment(CardBuilder $card, int $amount)
* $type defaults to REPEATED_PAYMENT but on first
* use should use INITIAL_PAYMENT.
*
* @param string $registrationId
* @param int $amount
* @param string $type
* @param PaymentCard $card
* @param $owner
* @param int $amount
* @param string $type
*
* @return mixed|\Psr\Http\Message\ResponseInterface
*/
Expand All @@ -103,7 +105,7 @@ public function repeatedPayment(PaymentCard $card, $owner, int $amount, string $
'currency' => 'ZAR',
'paymentType' => self::DEBIT,
'recurringType' => $type,
'merchantTransactionId' => class_basename($owner) . '-' . $owner->id
'merchantTransactionId' => class_basename($owner) . '-' . $owner->id,
],
]
)->getBody()->getContents();
Expand All @@ -118,7 +120,6 @@ public function repeatedPayment(PaymentCard $card, $owner, int $amount, string $
}

return false;

} catch (ClientException $e) {
$this->logErrors('repeatedPayment', $e);

Expand All @@ -131,10 +132,10 @@ public function repeatedPayment(PaymentCard $card, $owner, int $amount, string $
/**
* Perform a one click payment with a stored card.
*
* @param string $registrationId
* @param int $amount
* @param PaymentCard $card
* @param int $amount
*
* @return mixed|\Psr\Http\Message\ResponseInterface
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function oneClickPayment(PaymentCard $card, int $amount)
{
Expand All @@ -148,7 +149,7 @@ public function oneClickPayment(PaymentCard $card, int $amount)
'amount' => Currency::paymentFriendlyNumber($amount),
'currency' => 'ZAR',
'paymentType' => self::DEBIT,
'recurringType' => 'REPEATED'
'recurringType' => 'REPEATED',
],
]
)->getBody()->getContents();
Expand All @@ -166,7 +167,6 @@ public function oneClickPayment(PaymentCard $card, int $amount)
*
* @param string $paymentId
* @return mixed|\Psr\Http\Message\ResponseInterface
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function paymentStatus(string $paymentId)
{
Expand All @@ -190,7 +190,6 @@ public function paymentStatus(string $paymentId)
*
* @param string $registrationId
* @return mixed|\Psr\Http\Message\ResponseInterface
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function deleteCard(string $registrationId)
{
Expand Down

0 comments on commit 2a103cd

Please sign in to comment.