CBSubs - Create hosted Payment gateway with XML

11 years 5 months ago - 11 years 5 months ago #213169 by shardnzl
Hi.
Yesterday I bought an developer account to create my own payment gateway.
I read through the gateway API and looked at several examples and played around a little bit with it.

Now I wanted to create my own gateway.
My problem is, that the gateway I want to use requires XML data.

Just for testing I created the function getSinglePaymentRequstParams() with some sample data. But this function requires an array as return.

Is it possible to pass the XML data over to the site?
The data should look like this:

<GenerateRequest>
<PxPayUserId>TestAccount</PxPayUserId>
<PxPayKey>dc339b3126c8fbadf4b30b498ded6a62a17b5f831e3111116bd8e332c730bbc8</PxPayKey>
<AmountInput>2.06</AmountInput>
<CurrencyInput>NZD</CurrencyInput>
<MerchantReference>Test Transaction</MerchantReference>
<EmailAddress></EmailAddress>
<TxnData1>28 Grange Rd</TxnData1>
<TxnData2>Auckland</TxnData2>
<TxnData3>NZ</TxnData3>
<TxnType>Purchase</TxnType>
<TxnId>P777575CA3DDA78C</TxnId>
<BillingId></BillingId>
<EnableAddBillCard>0</EnableAddBillCard>
<UrlSuccess>www.mycompany.com/success.cfm
<UrlFail>www.mycompany.com/fail.cfm
<Opt>TO=0901142221</Opt>
</GenerateRequest>

And heres is the gateway I want to create:
www.paymentexpress.com/Technical_Resources/Ecommerce_Hosted/PxPay

What I already tried to just pass the XML file, save the XML as string or even convert it to an array, but without any success.

All I see when i go to the payment page is:
"Root Element is missing".
So something must be wrong with the data that is passed to it.

Hope you can help me with this.

Cheers

Please Log in to join the conversation.

11 years 5 months ago - 11 years 5 months ago #213193 by krileon
Hmm, that's like Google Checkout that I just finished creating. You need to send an HTTP request to the payment gateway with the post contents being XML. You'd then take the response, which should have a redirect URL in it, process it and redirect the user to the payment page. This is a significantly more advanced and complicated implementation, do they not have any other method of implementation?

The below is how you'd cause it to do an XML request redirect for the payment button.
	/**
	 * Returns single payment request parameters for gateway depending on basket (without specifying payment type)
	 *
	 * @param  cbpaidPaymentBasket  $paymentBasket   paymentBasket object
	 * @return array                                 Returns array $requestParams
	 */
	protected function getSinglePaymentRequstParams( $paymentBasket ) {
		return array(	'amount' => sprintf( '%0.2f', $paymentBasket->mc_gross ),
						'currency_code' => $paymentBasket->mc_currency,
						'custom' => $paymentBasket->id
					);
	}

	/**
	 * Optional function: only needed for recurring payments:
	 * Returns subscription request parameters for gateway depending on basket (without specifying payment type)
	 *
	 * @param  cbpaidPaymentBasket  $paymentBasket   paymentBasket object
	 * @return array                                 Returns array $requestParams
	 */
	protected function getSubscriptionRequstParams( $paymentBasket ) {
		return $this->getSinglePaymentRequstParams( $paymentBasket );
	}

	/**
	* Handles the gateway-specific result of payments (redirects back to this site and gateway notifications). WARNING: unchecked access !
	*
	* @param  cbpaidPaymentBasket  $paymentBasket  New empty object. returning: includes the id of the payment basket of this callback (strictly verified, otherwise untouched)
	* @param  array                $postdata       _POST data for saving edited tab content as generated with getEditTab
	* @param  string               $result         result= get parameter, other than 'notify', 'success' or 'cancel'.
	* @return string                               HTML to display if frontend, text to return to gateway if notification, FALSE if registration cancelled and ErrorMSG generated, or NULL if nothing to display
	*/
	protected function handleOtherResult( $paymentBasket, $postdata, $result ) {
		$return												=	null;

		if ( $result == 'payment' ) {
			$paymentBasketId								=	(int) cbGetParam( $postdata, 'custom', 0 );
			$exists											=	$paymentBasket->load( (int) $paymentBasketId );

			if ( $exists && ( sprintf( '%.2f', $paymentBasket->mc_gross ) == cbGetParam( $postdata, 'amount' ) ) && ( $paymentBasket->mc_currency == cbGetParam( $postdata, 'currency_code' ) ) ) {
				$request									=	'YOUR_XML_REQUEST';

				$response									=	null;
				$status										=	null;
				$error										=	$this->_httpsRequest( YOUR_XML_REQUEST_URL, $request, 45, $response, $status, 'post', 'xml', '*/*', true, 443 );

				cbimport( 'cb.xml.simplexml' );

				$requestdata								=	null;

				if ( $response ) {
					$xmlresponse							=	new CBSimpleXMLElement( $response );

					if ( $xmlresponse ) {
						$requestdata						=	$this->xmlTagValuesToArray( $xmlresponse );
					}
				}

				if ( ( ! $error ) && ( $status == 200 ) && $requestdata ) {
					$redirect								=	cbGetParam( $requestdata, 'YOUR_REQUEST_RESPONSE_REDIRECT_URL' );

					if ( $redirect ) {
						cbRedirect( $redirect );
					} else {
						$this->_setLogErrorMSG( 3, null, $this->getPayName() . ': merchantCheckout responded without a redirect url! Error: ' . cbGetParam( $requestdata, 'error-message' ), CBPTXT::T( 'Checkout failed.' ) . ' ' . CBPTXT::T( 'Please contact site administrator to check error log.' ) );

						$return								=	false;
					}
				} else {
					if ( $requestdata ) {
						$this->_setLogErrorMSG( 3, null, $this->getPayName() . ': merchantCheckout failed to respond! Error: ' . cbGetParam( $requestdata, 'error-message' ), CBPTXT::T( 'Checkout failed.' ) . ' ' . CBPTXT::T( 'Please contact site administrator to check error log.' ) );
					} else {
						$this->_setLogErrorMSG( 3, null, $this->getPayName() . ': merchantCheckout failed to respond. Please check Merchant ID and Merchant Key settings', CBPTXT::T( 'Checkout failed.' ) . ' ' . CBPTXT::T( 'Please contact site administrator to check error log.' ) );
					}

					$return									=	false;
				}
			} else {
				$this->_setErrorMSG( CBPTXT::T( 'Payment basket does not login.' ) );

				$return										=	false;
			}
		}

		return $return;
	}


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

11 years 5 months ago - 11 years 5 months ago #213223 by shardnzl
That is what I already tried.

But the XML needs a <GenerateRequest> at the beginning and a </GenerateRequest>
at the end. Otherwise it shows an error "Root element is missing".
I even tried
$result[GenerateRequest][amount]=sprintf( '%0.2f', $paymentBasket->mc_gross );
return $result;
But the first element of the array needs to be a String.

Any other suggestions?

Please Log in to join the conversation.

11 years 5 months ago - 11 years 4 months ago #213260 by krileon
Where it says YOUR_XML_REQUEST is where you type out your XML requests. Example as follows.
<GenerateRequest>
	<PxPayUserId>' . $this->getAccountParam( 'pspid' ) . '</PxPayUserId>
	<PxPayKey>' . $this->getAccountParam( 'pspkey' ) . '</PxPayKey>
	<AmountInput>' . sprintf( '%.2f', $paymentBasket->mc_gross ) . '</AmountInput>
	<CurrencyInput>' . $paymentBasket->mc_currency . '</CurrencyInput>
	<MerchantReference>' . htmlspecialchars( $paymentBasket->item_name ) . '</MerchantReference>
	<EmailAddress></EmailAddress>
	<TxnData1>28 Grange Rd</TxnData1>
	<TxnData2>Auckland</TxnData2>
	<TxnData3>NZ</TxnData3>
	<TxnType>Purchase</TxnType>
	<TxnId>' . $paymentBasket->id . '</TxnId>
	<BillingId></BillingId>
	<EnableAddBillCard>0</EnableAddBillCard>
	<UrlSuccess>' . $this->getSuccessUrl( $paymentBasket ) . '</UrlSuccess>
	<UrlFail>' . $this->getCancelUrl( $paymentBasket ) . '</UrlFail>
	<Opt>TO=0901142221</Opt>
</GenerateRequest>

You're literally typing out the XML requests. You can't format it as an array. You'll need to reference your payment gatways API to best format this and provide the information the gateway, and your self when the gateway responds, needs.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.276 seconds

Facebook Twitter LinkedIn