5
votes

I have php code to charge credit card via stripe I am beginner in php classes, so i don't know how to tell if the payment is succeed or not

<?
require_once('lib/Stripe.php');
Stripe::setApiKey("sk_test_123ABC");
if(isset($_POST)) {
$payment = Stripe_Charge::create(array(
'amount'        => '50',

'currency'      => 'usd',

'card'          => array(
'number'=> '4242424242424242',
'exp_month' => '12',
'exp_year'=> '14',
'cvc'=> '123'),
'description'   => 'New payment'
)); }

print_r($payment);
?>

Results

Stripe_Charge Object
(
    [_apiKey:protected] => sk_test_123ABC
    [_values:protected] => Array
        (
            [id] => ch_157h99GwRVG4EfR7dCxslaAs
            [object] => charge
            [created] => 1418105445
            [livemode] => 
            [paid] => 1
            [amount] => 50
            [currency] => usd
            [refunded] => 
            [captured] => 1
            [refunds] => Stripe_List Object
                (
2

2 Answers

3
votes

Your question has its answer.If an object is returned of stripecharge object that means the payment was successfull.

2
votes

Sorry but is there a way to focus on an error too? The above only confirms if charge was successful or no. It doesn't state the reason for rejection.

error:
    message: "Your card has insufficient funds."
    type: "card_error"
    code: "card_declined"
    charge: ch_12asdasweAAFdgooXDUd2tvKJgW

Sorry could not post a comment, due to less reputation. :(