<?php
session_start();
require './PaypalBase.php';
if(count($_POST) > 0) {
$dataArray = array(
"intent" => "sale",
"payer" => array(
"payment_method" => "credit_card",
"funding_instruments" => array(
array (
"credit_card" => array(
"number" => $_POST["card"],
"type" => "visa",
"expire_month" => $_POST["cardMonth"],
"expire_year" => $_POST["cardYear"],
"cvv2" => $_POST["cardCvv"],
"first_name" => $_POST["firstName"],
"last_name" => $_POST["lastName"]
)
)
)
),
"transactions" => array(
array(
"amount" => array(
"total" => floatval($_POST["subTotal"]) + floatval($_POST["tax"]) + floatval($_POST["shipping"]),
"currency" => $_POST["currency"],
"details" => array(
"subtotal" => floatval($_POST["subTotal"]),
"tax" => floatval($_POST["tax"]),
"shipping" => floatval($_POST["shipping"])
)
)
)
)
);
$paymentArray = PaypalBase::createPayment($dataArray);
if($paymentArray != NULL) {
PaypalBase::printR($paymentArray); return;
} else {
echo "<b>Error in payment</b>";
}
} else {
$_POST["card"] = "4417119669820331"; /* Test credit card */
$_POST["firstName"] = "Pritom";
$_POST["lastName"] = "Kumar Mondal";
$_POST["cardMonth"] = "06";
$_POST["cardYear"] = "2018";
$_POST["cardCvv"] = "123";
$_POST["subTotal"] = "20";
$_POST["tax"] = "10";
$_POST["shipping"] = "10";
$_POST["currency"] = "USD";
}
?>
<form method="POST">
<table>
<tr>
<td colspan="2"><i>Card Information</i></td>
</tr>
<tr>
<td>Card Number</td>
<td><input name="card" value="<?php echo $_POST["card"]; ?>"/></td>
</tr>
<tr>
<td>Card Name</td>
<td>
<input name="firstName" value="<?php echo $_POST["firstName"]; ?>"/>
<input name="lastName" value="<?php echo $_POST["lastName"]; ?>"/>
</td>
</tr>
<tr>
<td>Card Expiry</td>
<td>
<input name="cardMonth" value="<?php echo $_POST["cardMonth"]; ?>"/>
<input name="cardYear" value="<?php echo $_POST["cardYear"]; ?>"/>
</td>
</tr>
<tr>
<td>Card CVV</td>
<td><input name="cardCvv" value="<?php echo $_POST["cardCvv"]; ?>"/></td>
</tr>
<tr>
<td colspan="2"><i>Product Information</i></td>
</tr>
<tr>
<td>Currency</td>
<td><input name="currency" value="<?php echo $_POST["currency"]; ?>"/></td>
</tr>
<tr>
<td>Sub Total</td>
<td><input name="subTotal" value="<?php echo $_POST["subTotal"]; ?>"/></td>
</tr>
<tr>
<td>Tax</td>
<td><input name="tax" value="<?php echo $_POST["tax"]; ?>"/></td>
</tr>
<tr>
<td>Shipping</td>
<td><input name="shipping" value="<?php echo $_POST["shipping"]; ?>"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Pay..."/></td>
</tr>
</table>
</form>