양식을 제출하고 자바 스크립트로 처리 한 다음 PHP +로 API 호출을 한 다음 감사 메시지를 표시하거나 오류 배열을 표시하고 싶습니다. API로HTML 양식 처리 및 숨기기에 대한 도움말을 찾으십시오.
지금까지 나는 그 전화를 성공적으로 할 수 있었지만, 고마워하면서 전화를 받았지만 이후에는 양식을 숨길 수 없었습니다.
http://www.wilsonkeenan.com/learningphp/DoDirectPayment.php
내가 잘못 뭘하는지에 대한 어떤 생각? 모든 지침을 많이 주시면 감사하겠습니다.
<?php
if (isset($_POST['submitted'])){
session_start();
require_once 'CallerService.php';
/**
* Get required parameters from the web form for the request
*/
$paymentType =urlencode($_POST['paymentType']);
$firstName =urlencode($_POST['firstName']);
$lastName =urlencode($_POST['lastName']);
$creditCardType =urlencode($_POST['creditCardType']);
$creditCardNumber = urlencode($_POST['creditCardNumber']);
$expDateMonth =urlencode($_POST['expDateMonth']);
// Month must be padded with leading zero
$padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT);
$expDateYear =urlencode($_POST['expDateYear']);
$cvv2Number = urlencode($_POST['cvv2Number']);
$address1 = urlencode($_POST['address1']);
$address2 = urlencode($_POST['address2']);
$city = urlencode($_POST['city']);
$state =urlencode($_POST['state']);
$zip = urlencode($_POST['zip']);
$countrycode = urlencode($_POST['countrycode']);
$amount = urlencode($_POST['amount']);
//$currencyCode=urlencode($_POST['currency']);
$currencyCode="USD";
$paymentType=urlencode($_POST['paymentType']);
/* Construct the request string that will be sent to PayPal.
The variable $nvpstr contains all the variables and is a
name value pair string with & as a delimiter */
$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=$countrycode&CURRENCYCODE=$currencyCode";
/* Make the API call to PayPal, using API signature.
The API response is stored in an associative array called $resArray */
$resArray=hash_call("doDirectPayment",$nvpstr);
/* Display the API response back to the browser.
If the response from PayPal was a success, display the response parameters'
If the response was an error, display the errors received using APIError.php.
*/
$ack = strtoupper($resArray["ACK"]);
if($ack!="SUCCESS") {
$_SESSION['reshash']=$resArray;
$location = "APIError.php";
header("Location: $location");
} elseif ($ack =="SUCCESS") {
echo '<h1>Thank you</h1>';
}
}
else {
// Display Form
}
?>
<form method="POST" id="donate" action="" name="DoDirectPaymentForm">
<!--Payment type is <?=$paymentType?><br> -->
<input type=hidden name=paymentType value="<?php echo $paymentType?>" >
<fieldset>
<div>
<label class="label">First Name:</label>
<input type=text size=36 maxlength=32 name=firstName class="required" value=John>
</div>
</div>
<input type="hidden" name="submitted" value="1">
<input type=Submit value=Submit>
</div>
고맙습니다. 매우 도움이됩니다. 완벽하게 작동합니다. 이제 나의 과제는 내 작업을 Wordpress에서 모두 작동하도록하는 것입니다. 누구나 Wordpress에 PHP 폼 핸들러를 통합 한 경험이 있습니까? –
죄송합니다. 내 모든 코드를 작성하고 WordPress에 대한 경험이 전혀 없습니다. – WebChemist
WP는 쉽습니다. 그것은 단지 기본적인 PHP입니다. wp 변수에 액세스해야 할 때 재미있어 할 수 있지만 바보 같은 이름과 끔찍한 기능 기반 전달 시스템에 익숙해집니다. –