forked from LiveCarta/PayPal-PHP-SDK
Enabled Payment Experience
- Updated Api to enabled Payment Experience - Updated Tests and Samples - Added Json Validator - Ability for PPModel to return array of self objects
This commit is contained in:
@@ -13,26 +13,48 @@ use PayPal\Api\Transaction;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
|
||||
|
||||
function print_result($title, $objectName, $objectId = null, $output = null)
|
||||
{
|
||||
echo "<h3>$title</h3>";
|
||||
|
||||
if ($objectId) {
|
||||
echo "<div> Created " . ($objectName ? $objectName : "Object") . " with ID: $objectId</div>";
|
||||
}
|
||||
|
||||
if ($output) {
|
||||
if (is_a($output, 'PayPal\Common\PPModel')) {
|
||||
/** @var $output \PayPal\Common\PPModel */
|
||||
echo "<pre>" . $output->toJSON(JSON_PRETTY_PRINT) . "</pre>";
|
||||
} elseif (is_string($output)) {
|
||||
echo "<pre>$output</pre>";
|
||||
}
|
||||
}
|
||||
echo "<hr />";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* ### getBaseUrl function
|
||||
* // utility function that returns base url for
|
||||
* // determining return/cancel urls
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getBaseUrl() {
|
||||
function getBaseUrl()
|
||||
{
|
||||
|
||||
$protocol = 'http';
|
||||
if ($_SERVER['SERVER_PORT'] == 443 || (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on')) {
|
||||
$protocol .= 's';
|
||||
$protocol_port = $_SERVER['SERVER_PORT'];
|
||||
} else {
|
||||
$protocol_port = 80;
|
||||
}
|
||||
$protocol = 'http';
|
||||
if ($_SERVER['SERVER_PORT'] == 443 || (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on')) {
|
||||
$protocol .= 's';
|
||||
$protocol_port = $_SERVER['SERVER_PORT'];
|
||||
} else {
|
||||
$protocol_port = 80;
|
||||
}
|
||||
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
$port = $_SERVER['SERVER_PORT'];
|
||||
$request = $_SERVER['PHP_SELF'];
|
||||
return dirname($protocol . '://' . $host . ($port == $protocol_port ? '' : ':' . $port) . $request);
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
$port = $_SERVER['SERVER_PORT'];
|
||||
$request = $_SERVER['PHP_SELF'];
|
||||
return dirname($protocol . '://' . $host . ($port == $protocol_port ? '' : ':' . $port) . $request);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,51 +63,52 @@ function getBaseUrl() {
|
||||
* @param PayPal\Api\ApiContext apiContext
|
||||
* @return PayPal\Api\Authorization
|
||||
*/
|
||||
function createAuthorization($apiContext) {
|
||||
$addr = new Address();
|
||||
$addr->setLine1("3909 Witmer Road")
|
||||
->setLine2("Niagara Falls")
|
||||
->setCity("Niagara Falls")
|
||||
->setState("NY")
|
||||
->setPostalCode("14305")
|
||||
->setCountryCode("US")
|
||||
->setPhone("716-298-1822");
|
||||
|
||||
$card = new CreditCard();
|
||||
$card->setType("visa")
|
||||
->setNumber("4417119669820331")
|
||||
->setExpireMonth("11")
|
||||
->setExpireYear("2019")
|
||||
->setCvv2("012")
|
||||
->setFirstName("Joe")
|
||||
->setLastName("Shopper")
|
||||
->setBillingAddress($addr);
|
||||
|
||||
$fi = new FundingInstrument();
|
||||
$fi->setCreditCard($card);
|
||||
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod("credit_card")
|
||||
->setFundingInstruments(array($fi));
|
||||
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setDescription("Payment description.");
|
||||
|
||||
$payment = new Payment();
|
||||
function createAuthorization($apiContext)
|
||||
{
|
||||
$addr = new Address();
|
||||
$addr->setLine1("3909 Witmer Road")
|
||||
->setLine2("Niagara Falls")
|
||||
->setCity("Niagara Falls")
|
||||
->setState("NY")
|
||||
->setPostalCode("14305")
|
||||
->setCountryCode("US")
|
||||
->setPhone("716-298-1822");
|
||||
|
||||
// Setting intent to authorize creates a payment
|
||||
// authorization. Setting it to sale creates actual payment
|
||||
$payment->setIntent("authorize")
|
||||
->setPayer($payer)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
$paymnt = $payment->create($apiContext);
|
||||
$resArray = $paymnt->toArray();
|
||||
|
||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||
$card = new CreditCard();
|
||||
$card->setType("visa")
|
||||
->setNumber("4417119669820331")
|
||||
->setExpireMonth("11")
|
||||
->setExpireYear("2019")
|
||||
->setCvv2("012")
|
||||
->setFirstName("Joe")
|
||||
->setLastName("Shopper")
|
||||
->setBillingAddress($addr);
|
||||
|
||||
$fi = new FundingInstrument();
|
||||
$fi->setCreditCard($card);
|
||||
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod("credit_card")
|
||||
->setFundingInstruments(array($fi));
|
||||
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setDescription("Payment description.");
|
||||
|
||||
$payment = new Payment();
|
||||
|
||||
// Setting intent to authorize creates a payment
|
||||
// authorization. Setting it to sale creates actual payment
|
||||
$payment->setIntent("authorize")
|
||||
->setPayer($payer)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
$paymnt = $payment->create($apiContext);
|
||||
$resArray = $paymnt->toArray();
|
||||
|
||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user