-
Hi, Suppose our app needs to access the PayPal API,
Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
In this class you would have methods such as
use App\Data\PayPal\Token;
use App\Domains\PayPal\PayPalClient;
class AuthenticateWithPayPalJob
{
public function handle(PayPalClient $client): Token
{
$response = $client->authenticate(...);
// parse response into a Token object
return Token::makeFromResponse($response);
}
} To deal with the token there are two approaches:
I know these examples may be irrelevant but i hope it helps 😅 |
Beta Was this translation helpful? Give feedback.
-
Do you mean it will look like below? class CheckBalanceFeature
{
function handle()
{
$ppc = new \Domains\PayPal\PayPalClient($username, $password);
$token = $this->run(AuthenticateWithPayPalJob::class, ["PayPalClient" => $ppc]);
$this->run(CheckBalancePayPalJob::class, ["token" => $token]);
}
} In other words, we will not have |
Beta Was this translation helpful? Give feedback.
-
Yes, very close! I can suggest a few enhancements to the above:
Here's how it would look like after the above (though not sure if i understand correctly whether you should or should not have class CheckBalanceFeature
{
public function handle()
{
$token = $this->run(AuthenticateWithPayPalJob::class, [
'username' => $username,
'password' => $password,
]);
$this->run(CheckPayPalBalanceJob::class, compact('token'));
}
} And in class AuthenticateWithPayPalJob
{
private $username;
private $password;
public function __construct(string $username, string $password)
{
$this->username = $username;
$this->password = $password;
}
public function handle(PayPalClient $client)
{
return $client->authenticate($this->username, $this->password);
}
} |
Beta Was this translation helpful? Give feedback.
-
Hmm... interesting. Thanks. |
Beta Was this translation helpful? Give feedback.
Yes, very close! I can suggest a few enhancements to the above:
PayPalClient
)AuthenticateWithPayPalJob
because it already knows which class it needs to deal withHere's how it would look like after the above (though not sure if i understand correctly whether you should or should not have
username
andpassword
).