2013-01-04 4 views
2

양식 제출 후 직접 지불 방식을 사용해야합니다. 양식은 카드 종류 (비자 또는 마스터), 카드 번호, 보안 번호, 유효 기간, 카드 이름, 주소, 주, 우편 번호, 국가, 전화 번호, 이메일 등과 같은 모든 카드 세부 사항에 대한 사이트에 표시됩니다. 양식 제출시 dodirect payment paypal을 사용하는 방법은 무엇입니까?

은 내가 dodirect 메서드를 사용하는 방법을 검색하고 찾을 내가 어떻게 내 사이트에있는 양식의 제출에이 코드를 사용하는 아이디어를 얻을하지 않았다

<?php 

/** DoDirectPayment NVP example; last modified 08MAY23. 
* 
* Process a credit card payment. 
*/ 

$environment = 'sandbox'; // or 'beta-sandbox' or 'live' 

/** 
* Send HTTP POST Request 
* 
* @param string The API method name 
* @param string The POST Message fields in &name=value pair format 
* @return array Parsed HTTP Response body 
*/ 
function PPHttpPost($methodName_, $nvpStr_) { 
    global $environment; 

    // Set up your API credentials, PayPal end point, and API version. 
    $API_UserName = urlencode('my_api_username'); 
    $API_Password = urlencode('my_api_password'); 
    $API_Signature = urlencode('my_api_signature'); 
    $API_Endpoint = "https://api-3t.paypal.com/nvp"; 
    if("sandbox" === $environment || "beta-sandbox" === $environment) { 
     $API_Endpoint = "https://api-3t.$environment.paypal.com/nvp"; 
    } 
    $version = urlencode('51.0'); 

    // Set the curl parameters. 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $API_Endpoint); 
    curl_setopt($ch, CURLOPT_VERBOSE, 1); 

    // Turn off the server and peer verification (TrustManager Concept). 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_POST, 1); 

    // Set the API operation, version, and API signature in the request. 
    $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_"; 

    // Set the request as a POST FIELD for curl. 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq); 

    // Get response from the server. 
    $httpResponse = curl_exec($ch); 

    if(!$httpResponse) { 
     exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')'); 
    } 

    // Extract the response details. 
    $httpResponseAr = explode("&", $httpResponse); 

    $httpParsedResponseAr = array(); 
    foreach ($httpResponseAr as $i => $value) { 
     $tmpAr = explode("=", $value); 
     if(sizeof($tmpAr) > 1) { 
      $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1]; 
     } 
    } 

    if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) { 
     exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint."); 
    } 

    return $httpParsedResponseAr; 
} 

// Set request-specific fields. 
$paymentType = urlencode('Authorization');    // or 'Sale' 
$firstName = urlencode('customer_first_name'); 
$lastName = urlencode('customer_last_name'); 
$creditCardType = urlencode('customer_credit_card_type'); 
$creditCardNumber = urlencode('customer_credit_card_number'); 
$expDateMonth = 'cc_expiration_month'; 
// Month must be padded with leading zero 
$padDateMonth = urlencode(str_pad($expDateMonth, 2, '0', STR_PAD_LEFT)); 

$expDateYear = urlencode('cc_expiration_year'); 
$cvv2Number = urlencode('cc_cvv2_number'); 
$address1 = urlencode('customer_address1'); 
$address2 = urlencode('customer_address2'); 
$city = urlencode('customer_city'); 
$state = urlencode('customer_state'); 
$zip = urlencode('customer_zip'); 
$country = urlencode('customer_country');    // US or other valid country code 
$amount = urlencode('example_payment_amuont'); 
$currencyID = urlencode('USD');       // or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD') 

// Add request-specific fields to the request string. 
$nvpStr = "&PAYMENTACTION=$paymentType&AMT=$amount&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber". 
      "&EXPDATE=$padDateMonth$expDateYear&CVV2=$cvv2Number&FIRSTNAME=$firstName&LASTNAME=$lastName". 
      "&STREET=$address1&CITY=$city&STATE=$state&ZIP=$zip&COUNTRYCODE=$country&CURRENCYCODE=$currencyID"; 

// Execute the API operation; see the PPHttpPost function above. 
$httpParsedResponseAr = PPHttpPost('DoDirectPayment', $nvpStr); 

if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) { 
    exit('Direct Payment Completed Successfully: '.print_r($httpParsedResponseAr, true)); 
} else { 
    exit('DoDirectPayment failed: ' . print_r($httpParsedResponseAr, true)); 
} 

?> 

아래로. 양식을 제출 한 후이를 사용하는 방법을 누군가가 도와 줄 수 있습니까?

미리 감사드립니다. :)

답변

2

정말 잘 작성된 기능이 아닙니다. 기본적으로 함수 내의 값을 채우지 않고 채우고 싶습니다. 상당히 거친 예제이며, 주석에 따라 2008 년에 마지막으로 업데이트 된 것을 볼 수 있습니다.

그러나 실제로 사용하려는 데이터로 "my_api_username"과 같은 항목을 표시하는 모든 자리 표시자를 사용하면됩니다.

작업하기가 훨씬 편한 경우 수년간 개발하여 유지 관리해온 PHP library for PayPal을 사용하는 것이 좋습니다. 현재이며 DoDirectPayment를 실행하기위한 간단한 샘플이 포함되어 있습니다. 몇 분 안에 시작하고 실행할 수 있습니다.

관심이 있다면 화면 공유를 통해 30 분간 무료 교육을 제공합니다.

+0

안녕하세요. 앤드류 감사합니다. 나는 이것을 시도 할 것이다 – user75472

+0

고마워 ..... 그게 효과가있어. – user75472

+0

이 지불은 안전한가요? 사이트가 사용자의 신용 카드 정보를 추적 할 수 있고 사용하지 못할 수도 있기 때문에 사용자는이 지불을합니까? 감사합니다 – user75472

1

사실 공식 SDK를 사용하여 제안하고 내부의 샘플을 확인 https://www.x.com/developers/paypal/documentation-tools/paypal-sdk-index#expresscheckoutnew

에서 사용할 수있는 공식 SDK를의 일환으로 DoDirectPayment에 해당하는 샘플이 있습니다. 문제가있는 경우 여기에 다시 게시하거나 문제를 열어주십시오. https://github.com/paypal/merchant-sdk-php/issues

+0

PayPal은 안타깝게도 SDK를 많이 제공합니다. –

+0

Andrew, PHP SDK를 나열 할 수있는 경우 PHP SDK에 필요한 기능에 대해 기꺼이 노력할 것입니다. 우리는 한 달 전에 큰 개조 작업을했습니다. 의견이나 문제를 https://github.com/paypal/merchant-sdk-php/issues에서 추가하십시오. –