Skip to content

Commit

Permalink
Update parameter names in PaymentHandlerInterface implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
damms005 committed Oct 25, 2024
1 parent 7440680 commit 75afcad
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/Contracts/PaymentHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public function proceedToPaymentGateway(Payment $payment, $redirect_or_callback_
* process it should confirm that the payment_processor_name for the transaction is the
* same as its own getUniquePaymentHandlerName() value, then handle the response and return the Payment object
*
* @param Request $request
* @param Request $paymentGatewayServerResponse
*
* @return Payment
*/
public function confirmResponseCanBeHandledAndUpdateDatabaseWithTransactionOutcome(Request $request): ?Payment;
public function confirmResponseCanBeHandledAndUpdateDatabaseWithTransactionOutcome(Request $paymentGatewayServerResponse): ?Payment;

public function getHumanReadableTransactionResponse(Payment $payment): string;

Expand Down
6 changes: 3 additions & 3 deletions src/Services/PaymentHandlers/Flutterwave.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ protected function sendUserToPaymentGateway(string $redirect_or_callback_url, Pa
exit;
}

public function confirmResponseCanBeHandledAndUpdateDatabaseWithTransactionOutcome(Request $request): ?Payment
public function confirmResponseCanBeHandledAndUpdateDatabaseWithTransactionOutcome(Request $paymentGatewayServerResponse): ?Payment
{
if (!$request->has('tx_ref')) {
if (!$paymentGatewayServerResponse->has('tx_ref')) {
return null;
}

$payment = $this->handleExternalWebhookRequest($request);
$payment = $this->handleExternalWebhookRequest($paymentGatewayServerResponse);

return $payment;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Services/PaymentHandlers/Interswitch.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function proceedToPaymentGateway(Payment $payment, $redirect_or_callback_
]);
}

public function confirmResponseCanBeHandledAndUpdateDatabaseWithTransactionOutcome(Request $request): ?Payment
public function confirmResponseCanBeHandledAndUpdateDatabaseWithTransactionOutcome(Request $paymentGatewayServerResponse): ?Payment
{
return null;
}
Expand Down
22 changes: 11 additions & 11 deletions src/Services/PaymentHandlers/Paystack.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,34 @@ public function proceedToPaymentGateway(Payment $payment, $redirect_or_callback_
/**
* This is a get request. (https://developers.paystack.co/docs/paystack-standard#section-4-verify-transaction)
*
* @param Request $request
* @param Request $paymentGatewayServerResponse
*
* @return Payment
*/
public function confirmResponseCanBeHandledAndUpdateDatabaseWithTransactionOutcome(Request $request): ?Payment
public function confirmResponseCanBeHandledAndUpdateDatabaseWithTransactionOutcome(Request $paymentGatewayServerResponse): ?Payment
{
if (!$request->has('reference')) {
if (!$paymentGatewayServerResponse->has('reference')) {
return null;
}

return $this->processValueForTransaction($request->reference);
return $this->processValueForTransaction($paymentGatewayServerResponse->reference);
}

/**
* For Paystack, this is a get request. (https://developers.paystack.co/docs/paystack-standard#section-4-verify-transaction)
*/
public function processValueForTransaction(string $transactionReferenceIdNumber): ?Payment
public function processValueForTransaction(string $paystackReference): ?Payment
{
throw_if(empty($transactionReferenceIdNumber));
throw_if(empty($paystackReference));

$verificationResponse = $this->verifyPaystackTransaction($transactionReferenceIdNumber);
$verificationResponse = $this->verifyPaystackTransaction($paystackReference);

// status should be true if there was a successful call
if (!$verificationResponse->status) {
throw new \Exception($verificationResponse->message);
}

$payment = $this->resolveLocalPayment($transactionReferenceIdNumber, $verificationResponse);
$payment = $this->resolveLocalPayment($paystackReference, $verificationResponse);

if ('success' === $verificationResponse->data['status']) {
if ($payment->payment_processor_name != $this->getUniquePaymentHandlerName()) {
Expand Down Expand Up @@ -104,7 +104,7 @@ public function reQuery(Payment $existingPayment): ?ReQuery
throw new \Exception($verificationResponse->message);
}

$payment = $this->resolveLocalPayment($existingPayment->transaction_reference, $verificationResponse);
$payment = $this->resolveLocalPayment($existingPayment->processor_transaction_reference, $verificationResponse);

if ('success' === $verificationResponse->data['status']) {
if ($payment->payment_processor_name != $this->getUniquePaymentHandlerName()) {
Expand Down Expand Up @@ -266,13 +266,13 @@ public function createPaymentPlan(string $name, string $amount, string $interval
return '';
}

protected function resolveLocalPayment(string $transactionReferenceIdNumber, PaystackVerificationResponse $verificationResponse): Payment
protected function resolveLocalPayment(string $paystackReferenceNumber, PaystackVerificationResponse $verificationResponse): Payment
{
return Payment::query()
/**
* normal transactions
*/
->where('processor_transaction_reference', $transactionReferenceIdNumber)
->where('processor_transaction_reference', $paystackReferenceNumber)

/**
* terminal POS transactions
Expand Down
6 changes: 3 additions & 3 deletions src/Services/PaymentHandlers/Remita.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ protected function getRrrToInitiatePayment(Payment $payment): string
return $responseJson['RRR'];
}

public function confirmResponseCanBeHandledAndUpdateDatabaseWithTransactionOutcome(Request $request): ?Payment
public function confirmResponseCanBeHandledAndUpdateDatabaseWithTransactionOutcome(Request $paymentGatewayServerResponse): ?Payment
{
if (!$request->has('RRR')) {
if (!$paymentGatewayServerResponse->has('RRR')) {
return null;
}

$rrr = $request->RRR;
$rrr = $paymentGatewayServerResponse->RRR;

$payment = Payment::where('processor_transaction_reference', $rrr)
->first();
Expand Down
8 changes: 4 additions & 4 deletions src/Services/PaymentHandlers/UnifiedPayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ public function proceedToPaymentGateway(Payment $payment, $redirect_or_callback_

/**
*
* @param Request $request
* @param Request $paymentGatewayServerResponse
*
* @return Payment
*/
public function confirmResponseCanBeHandledAndUpdateDatabaseWithTransactionOutcome(Request $request): ?Payment
public function confirmResponseCanBeHandledAndUpdateDatabaseWithTransactionOutcome(Request $paymentGatewayServerResponse): ?Payment
{
if (!$request->has('trxId')) {
if (!$paymentGatewayServerResponse->has('trxId')) {
return null;
}

$payment = Payment::where('processor_transaction_reference', $request->trxId)->first();
$payment = Payment::where('processor_transaction_reference', $paymentGatewayServerResponse->trxId)->first();

if (is_null($payment)) {
return null;
Expand Down

0 comments on commit 75afcad

Please sign in to comment.