Re: RFC: Credit card processing
| From: | Joe Stump | Date: | Sat, 13 Dec 2003 16:32:43 +0000 |
| Subject: | Re: RFC: Credit card processing | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-24389@lists.php.net to get a copy of this message | ||
If you're using get_class($foo) == 'PEAR_Error' you're missing the point
of PEAR_Error.
$result = $cc->process();
if(!Payment::isError($result))
{
echo $result->transactionID;
}
else
{
echo $result->getMessage();
}
--Joe
> Ian Eure wrote:
>> On Friday 12 December 2003 06:36 pm, Mike wrote:
>>
>>>>I'm leaning towards a simple success/failure model, and you can call a
>>>>function to get the exact error (which will vary from processor to
>>>>processor).
>>>
>>>I am writing some classes for Validate at the moment and have found the
>>>same, a true/false response is best.
>>>
>>
>> Well, best until we can overload '=='. But not too much more code is
>> required
>> to check a class of a return.
>>
>
> it may not be much extra, but it isnt 'nice'
>
> if (Validate::creditCard($ccno)){
> echo "valid";
> }
> else {
> echo "Invalid";
> }
>
> compared to
>
> $ret = Validate::creditCard($ccno)
> if (get_class($ret)=="PEAR_Result"){
> echo "Valid";
> }
> if (get_class($ret)=="PEAR_Error"){
> echo "Invalid"
> }
>
> It leaves a lot of room for errors with newbies who expect a true/false
> response (like 99% of the php functions that validate data
> (function_exists, preg_match))
>
> A true false, with status has the benefit of being able to have a
> two-tier return method.. you can do either basic or fine graned... eg
>
> //simple
> $result = Payment::myPay($mydata);
> if ($result){
> //success
> }
> else {
> // error
> }
>
> // fine
> $p = new Payment_Mypay();
> $result = $p->send($mydata);
> $status = $p->getStatus();
> switch ($status){
> case PEAR_PAYMENT_SUCCESS:
> echo 'your order has been confirmed, your stuff will be sent now';
> send_data_to_warehouse();
> break;
> case PEAR_PAYMENT_DEFERRED:
> echo 'your payment coundnt be processed now, it will be queued and
> processed shortly, we will write soon to confirm the transaction';
> send_data_to_clearing();
> break;
> case PEAR_PAYMENT_DECLINED:
> echo 'you do not appear to have sufficient funds.... you are not
> welcome here anymore, please leave';
> send_user_to_different_site();
> break;
> // etc...
> }
>
> I think that returning a Payment_Result object on error AND on success
> is better than Error/Result, at least all the data is contained within
> the same namespace... maybe that is the way to go
>
> Mike
>
>
>>
>>>You should also have a look at Validate (still in beta, so its only in
>>>cvs http://cvs.php.net/cvs.php/pear/Validate) it has a
>>>routine for
>>>checking credit card numbers. You might want to incorporate this.
>>>
>>
>> Yes, I'm alrady using it.
>
> --
> PEAR Development Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Joe Stump <joe@joestump.net>
http://www.joestump.net
"Label makers are proof God wants Sys Admins to be happy."