diff --git a/readme.md b/readme.md index 706d3d4..f088834 100644 --- a/readme.md +++ b/readme.md @@ -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 @@ -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. @@ -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); @@ -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 diff --git a/src/Api/PaymentMethods/CopyAndPay.php b/src/Api/PaymentMethods/CopyAndPay.php index e0ecd0a..96c1359 100644 --- a/src/Api/PaymentMethods/CopyAndPay.php +++ b/src/Api/PaymentMethods/CopyAndPay.php @@ -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; @@ -97,7 +98,7 @@ public function getCheckoutRegistrationResult($path, $owner) 'result' => $result, 'owner' => $owner ]); - + return $result; } @@ -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 */ @@ -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(); @@ -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 */ @@ -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) { diff --git a/src/Api/PaymentMethods/ServerToServer.php b/src/Api/PaymentMethods/ServerToServer.php index ddb959b..f2806b8 100644 --- a/src/Api/PaymentMethods/ServerToServer.php +++ b/src/Api/PaymentMethods/ServerToServer.php @@ -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; @@ -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) { @@ -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 */ @@ -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(); @@ -118,7 +120,6 @@ public function repeatedPayment(PaymentCard $card, $owner, int $amount, string $ } return false; - } catch (ClientException $e) { $this->logErrors('repeatedPayment', $e); @@ -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) { @@ -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(); @@ -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) { @@ -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) {