Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sagepay callback function is not taking sagepay tx_model #28

Closed
prajwolonta opened this issue Sep 13, 2014 · 2 comments
Closed

Sagepay callback function is not taking sagepay tx_model #28

prajwolonta opened this issue Sep 13, 2014 · 2 comments

Comments

@prajwolonta
Copy link

Hi
public function anyCallback() {

    // Gather the POST data.
    $post = $_POST;
    $host = Config::get('database.connections.mysql.host', 'localhost');
    $dbname = Config::get('database.connections.mysql.database', 'database');
    $dbuser = Config::get('database.connections.mysql.username', 'root');
    $dbpass = Config::get('database.connections.mysql.password', '');

    $this->storage = new Academe\SagePay\Model\TransactionPdo();
    $this->storage->setDatabase('mysql:host=' . $host . ';dbname=' . $dbname, $dbuser, $dbpass);
    $dbprefix = Config::get('database.connections.mysql.prefix', '');
    $this->storage->setTablename($dbprefix . 'sagepay_transactions');

    $this->server->setTransactionModel($this->storage);
    if ($this->server->getField('Status') == 'OK') {

the callback function is not taking $this->server->getField('Status') == 'OK'.. is there something i must consider?

Regards,
Prajwol

@judgej
Copy link
Member

judgej commented Sep 13, 2014

You are giving $this->server the ability to fetch the saved transaction from the database, by giving it the storage object. That's fine so far; you are doing the dependency injection.

What you then need to do, is tell the server object to fetch the saved transaction, based on the POSTed VenderTxCode, then do a security check between other posted data and other fields on the transaction. That is all handled by:

$result = $this->server->notification($post, $complete_page_url)

The $result will be a string that you echo (back to SagePay) then immediately exit.

So in summary, notification($post, $final_page) uses VendorTxCode in $post to fetch the transaction from the database, do some security checks, then update the transaction in the database with the remaining fields in $post (which includes the authentication status, and your $final_page can pick all that up). Then it generates the return data that the SagePay notification caller is expecting.

You may want to use different return URLs, depending upon the authentication result. If so, then look at $post['STATUS'] and choose a URL based on that. However, I have found that a single "complete" page is usually easier to handle. That page can look at any authentication status, whether OK or otherwise, and make its decisions on how to handle it, and how to present that result to the end user.

Hope that helps.

@prajwolonta
Copy link
Author

That helped a lot thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants