Skip to content

Commit c145fd3

Browse files
committed
Add logging and user ID handling in PaymentProcessingCoinsJob
This commit enhances the PaymentProcessingCoinsJob by adding logging for payment processing events and incorporating user ID handling in the job's constructor. Additionally, a new method for verifying coin transactions is introduced in the VerifyPayinService, improving the overall payment verification process. A public key for Coolpay is also added to the .env.ci file for better configuration management.
1 parent 84db591 commit c145fd3

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

app/Http/Controllers/Coins/InitPaymentController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use NotchPay\Payment;
66
use NotchPay\NotchPay;
77
use Illuminate\Http\Request;
8+
use Illuminate\Support\Facades\Log;
89
use App\Http\Controllers\Controller;
910
use Illuminate\Support\Facades\Auth;
1011
use Illuminate\Support\Facades\Http;
@@ -34,6 +35,8 @@ public function payin(Request $request){
3435
"message"=>"Le solde du compte du payeur est insuffisant.",
3536
]);
3637
}else{
38+
39+
3740

3841

3942
PaymentProcessingCoinsJob::dispatch($request->payinAmount,$userId,$responseData->transaction_ref);

app/Jobs/PaymentProcessingCoinsJob.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace App\Jobs;
44

55
use Illuminate\Bus\Queueable;
6+
use Illuminate\Support\Facades\Log;
67
use Illuminate\Support\Facades\Auth;
8+
use Illuminate\Support\Facades\Http;
79
use Illuminate\Queue\SerializesModels;
810
use Illuminate\Queue\InteractsWithQueue;
911
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -21,26 +23,41 @@ class PaymentProcessingCoinsJob implements ShouldQueue
2123

2224
public $amount;
2325
public $reference;
26+
public $userId;
2427

25-
public function __construct($amount,$reference)
28+
public function __construct($amount,$userId,$reference)
2629
{
2730
$this->amount=$amount;
28-
$this->reference=$this->reference;
31+
$this->reference=$reference;
32+
$this->userId=$userId;
2933
}
3034

3135
/**
3236
* Execute the job.
3337
*/
3438
public function handle(): void
3539
{
36-
$userId=Auth::guard('api')->user()->id;
40+
41+
Log::info("martin",[
42+
'ref'=>$this->reference
43+
]);
44+
$url = "https://my-coolpay.com/api/".env("PUBLIC_KEY_COOLPAY_COINS")."/checkStatus/".$this->reference;
3745

38-
$paymentStatus = (new VerifyPayinService())->verify($reference);
39-
$responseStatus = $paymentStatus->getData(true)['status'] ?? null;
46+
$response=Http::get($url);
47+
$responseData=json_decode($response);
48+
49+
$responseStatus = $responseData->transaction_status;
50+
Log::info('PaymentProcessingCoinsJob: Payment processing for job', [
51+
"amount" => $responseStatus,
52+
]);
4053
if (isset($responseStatus) && $responseStatus === "PENDING") {
4154

55+
Log::info('PaymentProcessingCoinsJob: Payment processing for job', [
56+
"amount" => $this->amount,
57+
"reference" => $this->reference
58+
]);
4259
// On redéclenche le job avec les mêmes données, pas d'objet Request
43-
Self::dispatch($amount, $reference)->delay(now()->addSeconds(15));
60+
Self::dispatch($this->amount, $this->reference)->delay(now()->addSeconds(15));
4461
}
4562
if (isset($responseStatus) && $responseStatus === "FAILED" || $responseStatus === "CANCELED") {
4663

@@ -49,7 +66,7 @@ public function handle(): void
4966
}
5067

5168
if (isset($responseStatus) && $responseStatus == 'SUCCESS') {
52-
(new ValidatePaymentCoinService())->handle($this->reference,$this->amount,$userId);
69+
(new ValidatePaymentCoinService())->handle($this->reference,$this->amount,$this->$userId);
5370
}
5471

5572
}

app/Services/Payment/Coolpay/VerifyPayinService.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Services\Payment\Coolpay;
44

5+
use Illuminate\Support\Facades\Log;
56
use Illuminate\Support\Facades\Auth;
67
use Illuminate\Support\Facades\Http;
78

@@ -16,4 +17,15 @@ public function verify($transaction_ref){
1617

1718
return response()->json(['status' => $responseData->transaction_status]);
1819
}
20+
21+
public function verifyCoins($transaction_ref){
22+
$url = "https://my-coolpay.com/api/".env("PUBLIC_KEY_COOLPAY_COINS")."/checkStatus/".$transaction_ref;
23+
24+
$response=Http::get($url);
25+
$responseData=json_decode($response);
26+
Log::info('level', [
27+
"amount" => $transaction_ref,
28+
]);
29+
return response()->json(['status' => $responseData->transaction_status]);
30+
}
1931
}

app/Services/Payment/ValidatePaymentCoinService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use App\Models\Shop;
66
use App\Models\Payment;
7-
use App\Services\Payment\Coolpay\VerifyPayinService;
7+
88

99
class ValidatePaymentCoinService
1010
{

0 commit comments

Comments
 (0)