diff --git a/sample/bootstrap.php b/sample/bootstrap.php index d930b4f..eb9fed9 100644 --- a/sample/bootstrap.php +++ b/sample/bootstrap.php @@ -5,10 +5,12 @@ // Include the composer autoloader if(!file_exists(__DIR__ .'/vendor/autoload.php')) { - echo "The 'vendor' folder is missing. You must run 'composer update' to resolve application dependencies.\nPlease see the README for more information.\n"; + echo "The 'vendor' folder is missing. You must run 'composer update --no-dev' to resolve application dependencies.\nPlease see the README for more information.\n"; exit(1); } require __DIR__ . '/vendor/autoload.php'; +require __DIR__ . '/common.php'; + define("PP_CONFIG_PATH", __DIR__); use PayPal\Rest\ApiContext; @@ -36,24 +38,3 @@ $apiContext->setConfig(array( */ -/** - * ### getBaseUrl function - * // utility function that returns base url for - * // determining return/cancel urls - * @return string - */ -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; - } - - $host = $_SERVER['HTTP_HOST']; - $port = $_SERVER['SERVER_PORT']; - $request = $_SERVER['PHP_SELF']; - return dirname($protocol . '://' . $host . ($port == $protocol_port ? '' : ':' . $port) . $request); -} diff --git a/sample/common.php b/sample/common.php new file mode 100644 index 0000000..a75d79c --- /dev/null +++ b/sample/common.php @@ -0,0 +1,91 @@ +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(); + + // 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']; +} diff --git a/sample/index.html b/sample/index.html index 648cf4d..c191506 100644 --- a/sample/index.html +++ b/sample/index.html @@ -13,124 +13,109 @@ .source { background: url('images/edt-format-source-button.png') no-repeat left top; } + .header { + font-weight: bold; + } + .header td { + padding: 10px 0px 10px 0px; + }
| Payments | +|||||
| Payment with a credit card | -+ | Direct credit card payments | Execute | -Source | |
| Payment with a PayPal Account | - -+ | PayPal account payments | Execute | - -Source | |
| Get Payment Details | -+ | Stored credit card payments | +Execute | +Source | +|
| Get payment details | Execute | - -Source | |||
| Get Payment History | -+ | Get payment history | Execute | -Source | |
| Get Sale Details | -+ | Get sale details | Execute | -Source | |
| Refund a Payment | -+ | Refund a payment | Execute | -Source | |
| Vault | +|||||
| Save a credit card | -Execute | -Source | |||
| Retrieve saved credit card | -Execute | -Source | |||
| Get Details of Authorized Payment | -+ | Delete saved credit card | +Execute | +Source | +|
| Authorization and capture | +|||||
| Get details of an authorized payment | Execute | -Source | |||
| Capture Authorized Payment | -+ | Capture an authorized payment | Execute | -Source | |
| Void Authorized Payment | -+ | Void an authorized payment | Execute | -Source | |
| Reauthorize a Payment | -+ | Reauthorize a payment | Execute | -Source | |
| Get Details of Captured Payment | -+ | Get details of a captured payment | Execute | -Source | |
| Refund Captured Payment | -+ | Refund captured payment | Execute | -Source | |
| Delete saved CreditCard | -- | Execute | -- | Source | -