The SwiftWave PHP SDK enables seamless integration of SwiftWave's secure money transaction functionalities into PHP-based applications. This SDK simplifies transaction management, allowing you to send and receive payments, access currency exchange, and leverage SwiftWave's robust features within your PHP projects.
To fund payments using SwiftWave:
// Payer Object
$payer = new Payer();
$payer->setPaymentMethod('SwiftWave'); // Your system name, e.g., SwiftWave
Specify a payment amount and the currency:
// Amount Object
$amountIns = new Amount();
$amountIns->setTotal(20)->setCurrency('USD'); // Provide a valid currency code
Create a Transaction resource where the amount object is set:
// Transaction Object
$trans = new Transaction();
$trans->setAmount($amountIns);
Set the URLs where buyers should redirect after a transaction is completed or canceled:
// RedirectUrls Object
$urls = new RedirectUrls();
$urls->setSuccessUrl('https://your-merchant-domain.com/example-success.php') // Success URL
->setCancelUrl('https://your-merchant-domain.com/'); // Cancel URL
Create a payment resource with Payer, Amount, RedirectUrls, and merchant Credentials (Client ID and Client Secret):
// Payment Object
$payment = new Payment();
$payment->setCredentials([
'client_id' => 'your_client_id_here', // Provide correct client ID
'client_secret' => 'your_client_secret_here' // Provide correct client secret
])
->setRedirectUrls($urls)
->setPayer($payer)
->setTransaction($trans);
try {
$payment->create(); // Create payment
header("Location: ".$payment->getApprovedUrl()); // Checkout URL
} catch (Exception $ex) {
print $ex;
exit;
}
Make sure to use the required SwiftWave API classes:
use SwiftWave\Api\Payer;
use SwiftWave\Api\Amount;
use SwiftWave\Api\Transaction;
use SwiftWave\Api\RedirectUrls;
use SwiftWave\Api\Payment;
- Ensure the provided client ID and client secret are accurate.
- Customize URLs according to your application's redirect requirements.
- Replace placeholders with actual values for smooth integration.