How can I pass a necessary parameter while instantiating an object from a .NET assembly using DOTNET in PHP 5?
The sample code that came with the .NET assembly shows how to do this is with VB and C#:
VB: Dim transaction As New Paymentech.Transaction(RequestType.CC_AUTHORIZE)
C#: Paymentech.Transaction(Paymentech.RequestType.CC_AUTHORIZE);
I've tried the following using PHP:
$transaction = new DOTNET("ptDotNetSDK20","Paymentech.Transaction(CC_AUTHORIZE) ")
and
$transaction = new DOTNET("ptDotNetSDK20","Paymentech.Transaction(RequestType.CC_AUTHORIZE) ")
and even
$transaction = new DOTNET("ptDotNetSDK20","Paymentech.Transaction(Paymentech.RequestType.CC_AUTHORIZE) ")
and each time I get errors "Failed to instantiate .Net object". I've even tried enclosing the parameter in single quotes, with no improvement.
If I leave out the parameter and just try:
$transaction = new DOTNET("ptDotNetSDK20","Paymentech.Transaction")
I am able to create the transaction, but am then told "Transaction Object is invalid" when I later try to use it, which makes sense since I didn't create it with the necessary parameter in the first place.
Can anyone help me?
TerryWell this is a new one on me; PHP and DOTNET. Why?? is my first response, but of course I'm a Microsoft-phobe.
SORRY, to fast with my reply - you've obviously already been there.I've been tasked with integrating our PHP ordering system with Chase's Paymentech Orbital credit card billing system. Chase's preferred method of communication is through their supplied DLLs. They offer VB and C# examples of doing this with either COM or .NET 1 or 2.0.
I can get PHP to communicate with .NET using the examples given on PHPFreaks, but it's the passing of the parameter that's got me stumped. I would try using com_set (<!-- m --><a class="postlink" href="http://uk.php.net/manual/en/function.com-set.php">http://uk.php.net/manual/en/function.com-set.php</a><!-- m -->)
com_set( $transaction, 'RequestType', 'CC_AUTHORIZE');
Total guess and probably too simplistic unless that is all the constructor does.Time to call Chase tech support. I will bet a dollar that they have a method for PHP.RequestType.CC_AUTHORIZE is a constant. This constant will not be defined in PHP so if you attempt to pass it as a parameter to any function it will yield a null value and a spit out a Notice (if the appropriate error reporting is set).
You will need to find the value of this constant in VB and use its raw value or define it as a constant manually in PHP.
' VB
MsgBox RequestType.CC_AUTHORIZE
In PHP:
class RequestType
{
const CC_AUTHORIZE = /* value shown in MsgBox probably an Integer */
}
/* now you should be able to pass arguments to the constructor as extra
arguments to the DOTNET constructor */
$transaction = new DOTNET("ptDotNetSDK20","Paymentech.Transaction", RequestType::CC_AUTHORIZE)
You should also take a look at the com_load_typelib (<!-- m --><a class="postlink" href="http://uk.php.net/manual/en/function.com-load-typelib.php">http://uk.php.net/manual/en/function.co ... ypelib.php</a><!-- m -->) function that defines the constants in a type library for you.I would try using com_set (<!-- m --><a class="postlink" href="http://uk.php.net/manual/en/function.com-set.php">http://uk.php.net/manual/en/function.com-set.php</a><!-- m -->)
com_set( $transaction, 'RequestType', 'CC_AUTHORIZE');
com_set has evidently been done away with in PHP5 and replaced by the OO syntax of
$transaction->RequestType = 'CC_AUTHORIZE';
But that doesn't seem to work either. RequestType.CC_AUTHORIZE is a constant. This constant will not be defined in PHP so if you attempt to pass it as a parameter to any function it will yield a null value and a spit out a Notice (if the appropriate error reporting is set).
Thanks for that pointer, although it doesn't seem to make a difference (the constant maps to the string 'CC.Authorize').
The class constructor for Paymentech.Transaction wants a parameter telling the constructor which kind of Transaction to create. If I create a Transaction without the parameter:
$transaction = new DOTNET("ptDotNetSDK20","Paymentech.Transaction")
I end up with a transaction, but not one I can further work with. So the option of creating a Transaction and then setting its Type isn't an option for me.
What I need is the ability to pass along a parameter when I create the thing, which PHP5 doesn't seem to be able to do.
The sample code that came with the .NET assembly shows how to do this is with VB and C#:
VB: Dim transaction As New Paymentech.Transaction(RequestType.CC_AUTHORIZE)
C#: Paymentech.Transaction(Paymentech.RequestType.CC_AUTHORIZE);
I've tried the following using PHP:
$transaction = new DOTNET("ptDotNetSDK20","Paymentech.Transaction(CC_AUTHORIZE) ")
and
$transaction = new DOTNET("ptDotNetSDK20","Paymentech.Transaction(RequestType.CC_AUTHORIZE) ")
and even
$transaction = new DOTNET("ptDotNetSDK20","Paymentech.Transaction(Paymentech.RequestType.CC_AUTHORIZE) ")
and each time I get errors "Failed to instantiate .Net object". I've even tried enclosing the parameter in single quotes, with no improvement.
If I leave out the parameter and just try:
$transaction = new DOTNET("ptDotNetSDK20","Paymentech.Transaction")
I am able to create the transaction, but am then told "Transaction Object is invalid" when I later try to use it, which makes sense since I didn't create it with the necessary parameter in the first place.
Can anyone help me?
TerryWell this is a new one on me; PHP and DOTNET. Why?? is my first response, but of course I'm a Microsoft-phobe.
SORRY, to fast with my reply - you've obviously already been there.I've been tasked with integrating our PHP ordering system with Chase's Paymentech Orbital credit card billing system. Chase's preferred method of communication is through their supplied DLLs. They offer VB and C# examples of doing this with either COM or .NET 1 or 2.0.
I can get PHP to communicate with .NET using the examples given on PHPFreaks, but it's the passing of the parameter that's got me stumped. I would try using com_set (<!-- m --><a class="postlink" href="http://uk.php.net/manual/en/function.com-set.php">http://uk.php.net/manual/en/function.com-set.php</a><!-- m -->)
com_set( $transaction, 'RequestType', 'CC_AUTHORIZE');
Total guess and probably too simplistic unless that is all the constructor does.Time to call Chase tech support. I will bet a dollar that they have a method for PHP.RequestType.CC_AUTHORIZE is a constant. This constant will not be defined in PHP so if you attempt to pass it as a parameter to any function it will yield a null value and a spit out a Notice (if the appropriate error reporting is set).
You will need to find the value of this constant in VB and use its raw value or define it as a constant manually in PHP.
' VB
MsgBox RequestType.CC_AUTHORIZE
In PHP:
class RequestType
{
const CC_AUTHORIZE = /* value shown in MsgBox probably an Integer */
}
/* now you should be able to pass arguments to the constructor as extra
arguments to the DOTNET constructor */
$transaction = new DOTNET("ptDotNetSDK20","Paymentech.Transaction", RequestType::CC_AUTHORIZE)
You should also take a look at the com_load_typelib (<!-- m --><a class="postlink" href="http://uk.php.net/manual/en/function.com-load-typelib.php">http://uk.php.net/manual/en/function.co ... ypelib.php</a><!-- m -->) function that defines the constants in a type library for you.I would try using com_set (<!-- m --><a class="postlink" href="http://uk.php.net/manual/en/function.com-set.php">http://uk.php.net/manual/en/function.com-set.php</a><!-- m -->)
com_set( $transaction, 'RequestType', 'CC_AUTHORIZE');
com_set has evidently been done away with in PHP5 and replaced by the OO syntax of
$transaction->RequestType = 'CC_AUTHORIZE';
But that doesn't seem to work either. RequestType.CC_AUTHORIZE is a constant. This constant will not be defined in PHP so if you attempt to pass it as a parameter to any function it will yield a null value and a spit out a Notice (if the appropriate error reporting is set).
Thanks for that pointer, although it doesn't seem to make a difference (the constant maps to the string 'CC.Authorize').
The class constructor for Paymentech.Transaction wants a parameter telling the constructor which kind of Transaction to create. If I create a Transaction without the parameter:
$transaction = new DOTNET("ptDotNetSDK20","Paymentech.Transaction")
I end up with a transaction, but not one I can further work with. So the option of creating a Transaction and then setting its Type isn't an option for me.
What I need is the ability to pass along a parameter when I create the thing, which PHP5 doesn't seem to be able to do.