I think there's a bug here - the details field returned from paypal is an array but gets written to the db as text. This fixes it:


/**
 * Handles an incoming PayPal IPN.
 */
function simple_payments_paypal_ipn() {
	$ipn = $_POST;
	if(!_simple_payments_paypal_ipn_verify($ipn))
		return;

	if($ipn['payment_status'] != 'Completed')
	  return;


  $payment = simple_payments_explode_custom($ipn['custom']);

  $payment['gateway'] = 'paypal';
	$payment['currency'] = $ipn['mc_currency'];
	$payment['amount'] = bcmul($ipn['mc_gross'], 100);
  $payment['timestamp'] = strtotime($ipn['payment_date']);
	$payment['details'] = $ipn;
	

	simple_payments_payment_received($payment);
}


Comments

miiimooo’s picture

Oops.. that was the wrong piece of code. Here we go again:

/**
 * Handles a payment recieved from a payment gateway.
 *
 * @param $payment
 *   The payment that has been received.
 */
function simple_payments_payment_received($payment) {
  
  $payment['details'] = serialize($payment['details']);
  drupal_write_record('simple_payment', $payment);

  _simple_payments_payment_log($payment);
	simple_payments_payment_process($payment);
}
fuerst’s picture

The details field is marked as serialized in simple_payments.install so drupal_write_record() takes care of serializing it itself. There should be no need to do this in simple_payments_payment_received(). Do you get an error regarding an unserialized details field?

osopolar’s picture

StatusFileSize
new691 bytes

The details field is marked as serialized in simple_payments.install. This is a typo and needs to be serialize (without the d), see: http://api.drupal.org/api/group/schemaapi.

Patch attached.

osopolar’s picture

StatusFileSize
new1.15 KB

I think it also needs a hook_update_N to rebuild the schema cache.

fuerst’s picture

Ah, sure, serialize and not serialized. Being the reason of the error miiimooo probably experienced.

osopolar’s picture

StatusFileSize
new1.16 KB

The correct name of the update function is: simple_payments_update_6101

fuerst’s picture

Status: Needs review » Reviewed & tested by the community

Using the patch in #6 and a Paypal sandbox account it saves data serialized to simple_payment.details.

BTW: In the past I did not notice the serialize attribute of simple_payment.details so I did the serialization on my own.

jbrown’s picture

Version: 6.x-1.0 » 6.x-1.x-dev
Status: Reviewed & tested by the community » Fixed

$ret needs to be returned at the end of update functions.

Applied: http://drupal.org/cvs?commit=404042

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.