1. Go to this page and download the library: Download magpieim/magpie-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
magpieim / magpie-php example snippets
agpie\Magpie;
// Initialize the client
$magpie = new Magpie('sk_test_your_secret_key_here');
// Create a customer
$customer = $magpie->customers->create([
'name' => 'John Doe',
'email' => '[email protected]',
'phone' => '+639171234567'
]);
// Create a charge
$charge = $magpie->charges->create([
'amount' => 50000, // ₱500.00 in centavos
'currency' => 'php',
'source' => 'src_1234567890',
'description' => 'Payment for Order #1234'
]);
echo "Charge created: " . $charge['id'] . "\n";
agpie\Magpie;
use Magpie\DTOs\Requests\Customers\CreateCustomerRequest;
use Magpie\DTOs\Requests\Charges\CreateChargeRequest;
// Initialize the client
$magpie = new Magpie('sk_test_your_secret_key_here');
// Create a customer with full IDE support
$customerRequest = new CreateCustomerRequest(
email: '[email protected]',
description: 'Premium customer',
name: 'John Doe',
mobile_number: '+639171234567'
);
$customer = $magpie->customers->create($customerRequest);
// Create a charge with type safety
$chargeRequest = new CreateChargeRequest(
amount: 50000, // ₱500.00 in centavos
currency: 'php',
source: 'src_1234567890',
description: 'Payment for Order #1234',
capture: true
);
$charge = $magpie->charges->create($chargeRequest);
echo "Charge created: " . $charge->id . "\n"; // Type-safe property access
use Magpie\Laravel\Facades\Magpie;
// Using the facade
$customer = Magpie::customers()->create([
'name' => 'Jane Doe',
'email' => '[email protected]'
]);
// Or dependency injection
class PaymentController extends Controller
{
public function createPayment(Magpie\Magpie $magpie)
{
$charge = $magpie->charges->create([
'amount' => 25000, // ₱250.00
'currency' => 'php',
'source' => $request->source_id,
'description' => 'Order payment'
]);
return response()->json($charge);
}
}
// Arrays: No IDE help, runtime errors possible
$charge = $magpie->charges->create(['amount' => 50000, 'currency' => 'php']);
echo $charge['id']; // ❌ Might break if API changes
// DTOs: Full IDE support, compile-time safety
$request = new CreateChargeRequest(amount: 50000, currency: 'php');
$charge = $magpie->charges->create($request);
echo $charge->id; // ✅ IDE knows this exists