2

I'm trying to make a little shopping cart with CodeIgniter and I found CI-Merchant to work with payment gateways with this guide http://ci-merchant.org/ but I don't really understand how to make it works with Paypal Sandbox.

$this->load->library('merchant');
$this->merchant->load('paypal_express');
$settings = array(
    'username' => 'test@test.com',
    'password' => '********',
    'signature' => 'Test Store',
    'test_mode' => true);

$this->merchant->initialize($settings);
$params = array(
    'amount' => 12.00,
    'currency' => 'CAD',
    'return_url' => 'http://payment.test.com',
    'cancel_url' => 'http://payment.test.com/cancel');

$response = $this->merchant->purchase($params);
$this->load->view('welcome_message');

I know that this code can't do much but it do nothing at all. Just load the view and nothing happens, I don't understand. So, my question is, do you know tutorials or just how to make CI Merchant works with Paypal Sandbox? Thanks for the help.

ace
  • 7,293
  • 3
  • 23
  • 28
eoto
  • 63
  • 2
  • 9
  • try printing `$response` like this `print "
    "; var_dump($response); print "
    ";` before `$this->load-view('welcome_message);` to see the result.
    – ace Nov 05 '12 at 01:17
  • 2
    So I added `print "
    "; var_dump($response); print "
    ";` before `$this->load-view('welcome_message);` and I got `object(Merchant_response)[17] protected '_status' => string 'failed' (length=6) protected '_message' => string 'Security header is not valid' (length=28) ...` then I realized that we need to use "API and Payment Card Credentials" not the seller account's credentials. So now it works and I can continue to code!
    – eoto Nov 05 '12 at 02:10

1 Answers1

2

Ace's comment is spot on. There is nothing wrong with your code, but you need to inspect the $response object to see what the result (or error message) was.

$response = $this->merchant->purchase($params);
if ($response->success())
{
    // mark order as complete
    $gateway_reference = $response->reference();
}
else
{
    $message = $response->message();
    echo('Error processing payment: ' . $message);
    exit;
}

You can also simply try this to inspect the object:

$response = $this->merchant->purchase($params);
echo '<pre>';
print_r($response);
exit;
Adrian Macneil
  • 13,017
  • 5
  • 57
  • 70
  • Thanks, I found the problem! I was using the wrong credentials from Paypal so, it was just a code 18 Ahahahah! – eoto Nov 11 '12 at 01:41
  • I have take my credentials from https://developer.paypal.com/webapps/developer/applications/accounts Is it wrong or right link? –  Jun 01 '14 at 11:23