Goedenavond,
Ik ben bezig met het inbouwen van een iDeal betaalmethode via TargetPay, echter wil dit niet helemaal lukken...:$
Ik gebruik deze codes, ze zijn van TargetPay:
TargetPayIdeal.class.php
TargetPay.class.phpPHP Code:
<?php
/**
* TargetPay ideal example class
*
* SVE
* 11-01-2009
*/
# requires the init class
require_once ( 'TargetPay.class.php' );
class TargetPayIdeal extends TargetPay {
# ofcourse construct
public function __construct( $intRtlo ) {
# call parent constructor
parent::__construct( $intRtlo );
}
/**
* @Desc start payment
* @Return array ( trxid, idealReturnUrl )
*/
public function startPayment () {
try {
# Build parameter string
//$aParameters = $this->getBaseRequest();
$aParameters = array();
$aParameters['rtlo'] = $this->intRtlo;
$aParameters['bank'] = $this->idealIssuer;
$aParameters['description'] = $this->strDescription;
$aParameters['currency'] = $this->strCurrency;
$aParameters['amount'] = $this->idealAmount;
$aParameters['language'] = $this->strLanguage;
$aParameters['returnurl'] = $this->strReturnUrl;
$aParameters['reporturl'] = $this->strReportUrl;
# do request
$strResponse = $this->getResponse( $aParameters, 'https://www.targetpay.com/ideal/start?');
$aResponse = explode('|', $strResponse );
# Bad response
if ( !isset ( $aResponse[1] ) ) {
throw new Exception( 'Error' . $aResponse[0] );
}
$iTrxID = explode ( ' ', $aResponse[0] );
# We return TRXid and url to rederict
return array ( $iTrxID[1], $aResponse[1] );
}
catch( Exception $e ) {
# error, could not proceed
echo $e->getMessage();
}
}
/**
* Validate the payment now by trxId
*
* @return bool
*/
public function validatePayment ( $intTrxId, $iOnce = 1, $iTest = 0 ) {
try {
# Build parameter string
$aParameters = array();
$aParameters['rtlo'] = $this->intRtlo;
$aParameters['trxid'] = $intTrxId;
$aParameters['once'] = $iOnce;
$aParameters['test'] = $iTest;
# do request
$strResponse = $this->getResponse ( $aParameters , 'https://www.targetpay.com/ideal/check?');
$aResponse = explode('|', $strResponse );
# Bad response
if ( $aResponse[0] != '000000 OK' ) {
throw new Exception( $aResponse[0] );
}
return true;
}
catch( Exception $e ) {
# error, could not proceed
echo $e->getMessage();
}
}
/**
*
* @Desc set ideal return url
*
*/
public function setIdealReturnUrl ( $strReturnUrl ) {
$this->strReturnUrl = $strReturnUrl;
return $this;
}
/**
*
* @Desc set ideal return url
*
*/
public function setIdealReportUrl ( $strReportUrl ) {
$this->strReportUrl = $strReportUrl;
return $this;
}
/**
*
* @Desc set ideal description for transaction
*
*/
public function setIdealDescription ( $strDescription ) {
$this->strDescription = $strDescription;
return $this;
}
/**
* @Desc set ideal amount
*
*/
public function setIdealAmount ( $intIdealAmount ) {
# Is this a valid ideal amount?
if ( is_numeric ( $intIdealAmount ) && $intIdealAmount > 0 ) {
$this->idealAmount = $intIdealAmount;
}
else {
throw new Exception( 'Invalid ideal amount, please check.' );
}
return $this;
}
/**
* @Desc set ideal issuer
*
*/
public function setIdealissuer ( $intIdealIssuer ) {
$this->idealIssuer = $intIdealIssuer;
return $this;
}
/**
* Get available issuers, and return array
*
* @return array
*/
// public static function getBanks() {
// return array('0031'=>'ABN AMRO Bank', '0761'=>'ASN Bank', '0081'=>'Fortis Bank', '0091'=>'Friesland Bank', '0721'=>'ING Bank', '0021'=>'Rabobank', '0751'=>'SNS Bank', '0771'=>'SNS Regio Bank');
// }
}
?>
Hier moet ie verwerkt worden, ideal.phpPHP Code:
<?php
/**
* TargetPay Example class
*
* SVE
*
* 11-01-2009
*/
abstract class TargetPay {
/**
* @var int rtlo partner ID
*/
protected $intRtlo = 0;
/**
* @desc construction class
* @Var int rtlo partner ID
*/
public function __construct( $intRtlo ) {
$this->setRtlo ( $intRtlo );
}
/**
* Get response for a targetpay request
*
* @param array $aParams
* @return string
*/
protected function getResponse( $aParams, $sRequest = 'https://www.targetpay.com/api/plugandpay?' ) {
# convert params
$strParamString = $this->makeParamString( $aParams );
# get request
$strResponse = @file_get_contents( $sRequest . $strParamString);
if ( $strResponse === false )
throw new Exception('Could not fetch response');
return $strResponse;
}
/**
* Make string from params
*
* @param array $aParams
* @return string
*/
protected function makeParamString( $aParams ) {
$strString = '';
foreach ( $aParams as $strKey => $strValue )
$strString .= '&' . urlencode($strKey) . '=' . urlencode($strValue);
# remove first &
return substr( $strString ,1 ) ;
}
/**
* Get the base request with IP, RTLO, domain,
*
* @return array
*/
protected function getBaseRequest() {
# return array with base parameters
$aParams = array();
$aParams['action'] = 'start';
$aParams['ip'] = $_SERVER['REMOTE_ADDR'];
$aParams['domain'] = $this->strDomain ;
$aParams['rtlo'] = $this->intRtlo ;
return $aParams;
}
/**
* @desc set domain
*
*/
public function setDomain ( $strDomain ) {
$this->strDomain = $strDomain;
}
/**
* @desc set rtlo partner id
* @Var int rtlo partner ID
*/
public function setRtlo ( $intRtlo ) {
$this->intRtlo = $intRtlo;
}
/**
* Return rtlo
*
* @return int
*/
public function getRtlo () {
return $this->intRtlo;
}
}
?>
En op deze pagina heb ik ideal.php geïnclude:PHP Code:
<?php
/**
* Ideal example on how to use the ideal class!
*
* SVE
*
* 11-01-2009
*
*/
require_once ( 'TargetPayIdeal.class.php');
$iRtlo = 35348;
# Set ideal amount in cents so 500 cent will be 5 euro
$iAmount = 799;
# Set return url from your website
$iReturnurl = "http://onehosted.nl/msf/berichten.php";
# Set report url to recieve the status of transactions not retreived by the returnurl
$iReporturl = "http://onehosted.nl/msf/reportscript.php";
$iIssuer = $_GET[ "bank" ];
/**
* This function will validate the payment after returning from the bank
*/
# ?action=validate&trxid= 'trxid'
if ( isset ( $_GET['ec'] ) && isset ( $_GET['trxid'] ) ) {
# Init the class
$oIdeal = new TargetPayIdeal ( $iRtlo );
// $oIdeal->setDomain ( 'www.mijndomein.nl' );
if ( $oIdeal->validatePayment ( $_GET['trxid'] ) == true ) {
echo 'De betaling was geslaagd';
}
else {
echo 'De betaling was (nog) niet geslaagd';
}
}
elseif($iIssuer == "")
{
/*
* Choose your bank
*/
?>
<!-- DIT HEB IK ZELF GEDAAN (de php code in de action) ALLEEN WORDEN DE PARAMETERS NIET MEEGESTUURD! -->
<form method="get" name="idealform" action="http://www.targetpay.com/ideal/start?&rtlo=<?php echo $iRtlo; ?><?php echo $iIssuer; ?>">
<i>Maak een keuze uit de volgende banken...</i><br>
<select name="bank"><script src="http://www.targetpay.com/ideal/issuers-nl.js"></script></select>
<INPUT TYPE=submit VALUE="Ga verder"></form>
<?
}
else
{
/*
* Initiate payment
*/
ini_set ( 'display_errors' , '1');
# To initiate a payment, initiate the class
$oIdeal = new TargetPayIdeal ( $iRtlo );
# Set ideal amount in cents so 500 cent will be 5 euro
$oIdeal->setIdealAmount ( $iAmount );
# Set ideal issuer
$oIdeal->setIdealissuer ( $iIssuer );
# Set ideal description
$oIdeal->setIdealDescription ( 'Dit is een test betaling');
# Set return url, wich should return on succes
$oIdeal->setIdealReturnUrl ( $iReturnurl );
# Set report url
$oIdeal->setIdealReportUrl ( $iReporturl );
# Now we can initiate the payment
$aReturn = $oIdeal->startPayment();
# This is the transaction id
$intTrxId = $aReturn[0];
# this will be the bank url that will rederect to the bank.
$strBankURL = $aReturn[1];
# For check we can echo it here. (uncomment if you want to see. )
//echo 'Transaction ID: '. $intTrxId . '<br/>Bank URL: '. $strBankURL;
/**
* This haader function will redirect the browser to the bank
*/
}
?>
Het probleem is dat als de bank geselecteerd is, en er op 'Ga Verder' word gedrukt, hij niet de goede parameters meegeeft, welke wel zijn ingevuld.PHP Code:
<?php
session_start();
include("config.php");
include("TargetPay.class.php");
include("TargetPayIdeal.class.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-9735576-49']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<meta name="google-site-verification" content="jRkXoKxOrOrF-6H2CyIk3LNNjIYBHgXQoa7f282VQcE" />
<meta http-equiv="Content-Language" content="nl">
<meta name="description" content="">
<meta name="">
<meta name="author" content="">
<meta name="robots" content="index, follow">
<meta name="revisit-after" content="3 month">
</head>
<body>
<div id="header"></div>
<div id="menu"> <a href="#">Startpagina</a>
<a href="#">Registreren</a>
<a href="#">Foto's</a>
<a href="#">Leden</a>
<a href="#">Tell-a-friend</a>
<a href="#">Bookmark</a>
<a href="#">Info</a>
<a href="#">Contactformulier</a>
</div>
<?php
$bQuery = mysql_query("SELECT aan FROM berichten WHERE aan='".$_SESSION['gebruikersnaam']."' AND gelezen= 0 ");
$bAantal = mysql_num_rows($bQuery);
$bTotaal = $bAantal;
$query_credits = mysql_query("SELECT * FROM gebruikers WHERE gebruikersnaam='".$_SESSION['gebruikersnaam']."'");
while($rij_credits = mysql_fetch_array($query_credits)){
$credits_1 = $rij_credits['mail_credits'];
}
if(empty($_SESSION['gebruikersnaam'])){
echo'';
}else{
echo'<div id="leden_menu">
<a href="berichten.php"><img src="images/bericht.png" class="bericht" alt="Berichten" />Berichten <strong>('.$bAantal.')</strong></a>
<a href="uitloggen.php"><img src="images/uitloggen.png" class="uitloggen" alt="Uitloggen" /></a>
<a href="koopcredits.php"><img src="images/credits.png" class="credits" alt="Credits" />'.$credits_1.'</a>
<a href="profiel.php?gebruikersnaam='.$_SESSION['gebruikersnaam'].'"><img src="images/profiel.png" class="profiel" alt="Profiel" /></a>
</div>';
}
?>
<div class="container">
<div class="content-top">Mail credits kopen</div>
<div class="content-mid">
<?php
if(empty($_SESSION['gebruikersnaam'])){
echo'<div class="fout">Om deze pagina te zien moet je ingelogd zijn.</div>';
}else{
echo'Hier kan je mail credits kopen voor je account zodat je kunt mailen met de andere leden!<br /><br />';
echo'<strong>Tarieven*:</strong><br />10 credits - €7,99<br />15 credits - €14,99<br />30 credits - €24,99<br /><br />';
echo'Maak hieronder uw keuze om de credits te bestellen! Betaling gaat via iDeal (online overschrijven).';
echo'<br /><br />';
echo'<iframe src="ideal.php" frameborder="0" />';
}
?>
<br /><br /><font size="1">*Bedrag is inclusief btw!</font>
</div>
<div class="content-bottom"></div>
<div id="copyright">© Copyright 2010-2011 | Alle rechten voorbehouden</div>
</div>
</body>
</html>
Mvg,
Jos
- [PHP] iDeal api targetpay
-
25-11-2010, 20:21 #1
- Berichten
- 943
- Lid sinds
- 15 Jaar
[PHP] iDeal api targetpay
-
-
26-11-2010, 12:25 #2
- Berichten
- 750
- Lid sinds
- 15 Jaar
Re: [PHP] iDeal api targetpay
Ten eerste de pagina http://onehosted.nl/msf/reportscript.php werkt al niet
-
26-11-2010, 17:20 #3
- Berichten
- 943
- Lid sinds
- 15 Jaar
Re: [PHP] iDeal api targetpay
Klopt, maar die is pas later van belang, het gaat er nu om dat ik niet weet waarom de juiste waardes niet worden meegezonden...
Plaats een
- + Advertentie
- + Onderwerp
Marktplaats
Webmasterforum
- Websites algemeen
- Sitechecks
- Marketing
- Domeinen algemeen
- Waardebepaling
- CMS
- Wordpress
- Joomla
- Magento
- Google algemeen
- SEO
- Analytics
- Adsense
- Adwords
- HTML / XHTML
- CSS
- Programmeren
- PHP
- Javascript
- JQuery
- MySQL
- Ondernemen algemeen
- Belastingen
- Juridisch
- Grafisch ontwerp
- Hosting Algemeen
- Hardware Info
- Offtopic