Arkadaşlar selam
Projemde laravel/paypal paketi kullanmaya çalışıyorum yalnız şöyle bir sıkıntı var ki classım aşağıdaki gibi
class Paypal {
public static function __callStatic($method, $args) {
// if production mode...
if (Config::get('paypal.production_mode') === true) {
// use production credentials
$credentials = Config::get('paypal.production');
// use production endpoint
$endpoint = 'https://api-3t.paypal.com/nvp';
}
// if sandbox mode...
else {
// use sandbox credentials
$credentials = Config::get('paypal.sandbox');
// use sandbox endpoint
$endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
}
// build credentials
$params = array(
'VERSION' => '74.0',
'USER' => $credentials['username'],
'PWD' => $credentials['password'],
'SIGNATURE' => $credentials['signature'],
// 'METHOD' => 'setExpressCheckout',
'METHOD' => static::camelcase($method),
);
// build post data
$fields = http_build_query($params + $args[0]);
// curl request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$response = curl_exec($ch);
// if errors...
if (curl_errno($ch)) {
#$errors = curl_error($ch);
curl_close($ch);
// return false
return false;
}
// if NO errors...
else {
curl_close($ch);
// return array
parse_str($response, $result);
return $result;
}
}
public static function ipn() {
// only accept post data
if (Request::method() !== 'POST')
return false;
// if production mode...
if (Config::get('paypal.production_mode')) {
// use production endpoint
$endpoint = 'https://www.paypal.com/cgi-bin/webscr';
}
// if sandbox mode...
else {
// use sandbox endpoint
$endpoint = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
}
// build response
$fields = http_build_query(array('cmd' => '_notify-validate') + Input::all());
// curl request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// if errors...
if (curl_errno($ch)) {
#$errors = curl_error($ch);
curl_close($ch);
// return false
return false;
}
// if NO errors...
else {
curl_close($ch);
// if success...
if ($code === 200 and $response === 'VERIFIED') {
return true;
}
// if NOT success...
else {
return false;
}
}
}
protected static function camelcase($str) {
return preg_replace_callback('/(^|_)([a-z])/',
create_function ('$matches', 'return strtoupper($matches[2]);'), $str);
}
}
ve Controllerımda ki fonksiyon kodları da şu şekilde
public function postActionpaypal($merc_id) {
$methods = Input::get('methods');
if ($methods == 1) {
if (Request::method() == 'POST') {
$article = Package::find(Input::get('id'));
if (!$article || $article->price !== Input::get('price')) {
return Redirect::back();exit;
}
$response = Paypal::set_express_checkout(array(
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
'CURRENCYCODE' => 'EUR',
'LOCALCODE' => 'IT',
'DESC' => $article->description,
'AMT' => $article->price,
'RETURNURL' => public_path() . '/packages/return',
'CANCELURL' => public_path() . '/packages/cancel',
'CUSTOM' => 'article_id :' . $article->id
));
echo '<pre>'.print_r($response);
if (is_array($response) && $response['ACK'] == 'Success') {
return $token = $response['TOKEN'];
header( 'Location: https://www.paypal.com/webscr?cmd=_express-checkout&token=' . urlencode($token) );
exit;
} else {
return 'Bir hata var ! ' . $response['L_LONGMESSAGE0'];
}
if(!empty($response['TOKEN']) && $response['ACK'] == 'Success'){
$token = strip_tags($response['TOKEN'] );
header('Location: https:ww.sandbox.paypal.com/webscr?cmd=_express-checkout&token='.urlencode($token).'&useraction=commit');exit;
}else{
return 'Bir hata var ! '.$response['L_LONGMESSAGE0'];
}
}
} else {
return 'Henüz Kredi Kartı ile satış etkin değildir ! Geri gidiniz';
}
}
Yukarıda görüldüğü şekilde echo '<pre>'.print_r($response);$ersponse değişkenini ekrana bastığımda da
Array
(
[TIMESTAMP] => 2014-09-20T13:13:36Z
[CORRELATIONID] => 709afa26a4379
[ACK] => Failure
[VERSION] => 74.0
[BUILD] => 12932421
[L_ERRORCODE0] => 10471
[L_ERRORCODE1] => 10472
[L_SHORTMESSAGE0] => Transaction refused because of an invalid argument. See additional error messages for details.
[L_SHORTMESSAGE1] => Transaction refused because of an invalid argument. See additional error messages for details.
[L_LONGMESSAGE0] => ReturnURL is invalid.
[L_LONGMESSAGE1] => CancelURL is invalid.
[L_SEVERITYCODE0] => Error
[L_SEVERITYCODE1] => Error
)
Bu şekilde bir çıktı alıyorum
Şimdi sorun şu ki ben TOKEN şelinde bir değer almak zorundayımve bu değer bana dönmüyor
çünkü kodun header( 'Location:
https://www.paypal.com/webscr?cmd=_express-checkout&token=' . urlencode($token) ); bölümüne geçemiyorum o zaman
Nerede hata yapıyorum yada Paypal artık yönlendirme esnasında TOKEN istemiyor mu yada bunun yerine CORRELATIONID mi göndermem gerekecek , yardımlarınız için şimdiden teşekkürler
Selam ve dua ile