I really don't know what im doing right now..
in my class
use App\Paymongo\Payment;
/**
* @param array $data
* @param string $method
* @return string
*/
public function topUp(array $data, $method)
{
if ($method == 'gcash') {
$checkout = Payment::payWithGcash($data['amount']);
}
$attributes = $checkout->getAttributes();
event(new TopUpRequested($attributes['id'],$attributes['amount']));
return $attributes['redirect']['checkout_url'];
}
inside App\Paymongo\Payment
<?php
namespace App\Paymongo;
use Luigel\Paymongo\Facades\Paymongo;
class Payment extends Paymongo
{
/**
* @param float $amount
* @return Paymongo
*/
public function payWithGcash($amount)
{
return Paymongo::source()->create([
'type' => 'gcash',
'amount' => $amount,
'currency' => 'PHP',
'redirect' => [
'success' => route('top-up.success'),
'failed' => route('top-up.failed')
]
]);
}
}
in my test file i have this snippet
use App\Paymongo\Payment;
use Luigel\Paymongo\Paymongo;
/** @test */
public function test_can_create_transaction_when_topup_gcash()
{
$paymongo = Mockery::mock(Paymongo::class);
Payment::shouldReceive('payWithGcash')->once()
->shouldReceive('source')->andReturn($paymongo)
->shouldReceive('create')
->andReturn(json_decode('
{
"data": {
"id": "gggggg",
"type": "source",
"attributes": {
"amount": 10000,
"billing": null,
"currency": "PHP",
"description": null,
"livemode": false,
"redirect": {
"checkout_url": "link.com",
"failed": "http://localhost/failed",
"success": "http://localhost/success"
},
"statement_descriptor": null,
"status": "pending",
"type": "gcash",
"created_at": 1648140991,
"updated_at": 1648140991
}
}
}',true));
}
i got this error Received Mockery_2_Luigel_Paymongo_Paymongo::create(), but no expectations were specified but when i remove ->andReturn($paymongo), the error will be Call to a member function create() on null