static function create_from_pptxn($pptxn_id) { $t = new PayPalTxn($pptxn_id); # if it already has a payment_id, stop here and just return that id if ($t->payment_id() > 0) { return $t->payment_id(); } $student_id = $t->student_id(); if ($student_id === false) { return false; } $set = array('student_id' => $student_id, 'created_at' => 'NOW()'); $money = $t->money(); $set['currency'] = $money->code; $set['millicents'] = $money->millicents; $info = $t->infoarray(); if (!isset($info['item_number'])) { return false; } $d = new Document($info['item_number']); if ($d->failed()) { return false; } $set['document_id'] = $d->id; $p = new Payment(false); $payment_id = $p->add($set); $t->set(array('payment_id' => $payment_id)); return $payment_id; }
function testFromPPTXN() { # (id, student_id, document_id, currency, millicents, details, created_at) VALUES (4, 1, 1, 'EUR', 15000, 'PayPal transaction ID#: whatever', NOW()); # to test, delete existing payment, null out payment_id in pptxn, and see if it'll recreate it $x = new PayPalTxn(4); $x->set(array('payment_id' => 'NULL')); $z = new Payment(4); $z->kill(); $payment_id = Payment::create_from_pptxn($x->id); $z = new Payment($payment_id); $this->assertEquals(1, $z->student_id()); $this->assertEquals(1, $z->document_id()); $this->assertEquals('EUR', $z->currency()); $this->assertEquals(15000, $z->millicents()); $x = new PayPalTxn(4); $this->assertEquals($x->payment_id(), $z->id); }