recreate project

This commit is contained in:
root
2026-02-10 22:11:06 -05:00
commit 663c0cdbda
10149 changed files with 1379710 additions and 0 deletions
@@ -0,0 +1,83 @@
<?php
// # Create Bank Account Sample
// You can store credit card details securely
// with PayPal. You can then use the returned
// Bank Account id to process future payments.
// API used: POST /v1/vault/bank-accounts
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\BankAccount;
// ### Bank Account
// A resource representing a bank account that is
// to be stored with PayPal.
/*
{
"account_number": "4417119669820331",
"account_number_type": "IBAN",
"account_type": "SAVINGS",
"account_name": "Ramraj",
"check_type": "PERSONAL",
"auth_type": "WEB",
"bank_name": "CITI",
"country_code": "US",
"first_name": "Ramraj",
"last_name": "K",
"birth_date": "1987-08-13",
"billing_address": {
"line1": "52 N Main ST",
"city": "Johnstown",
"country_code": "US",
"postal_code": "43210",
"state": "OH",
"phone": "408-334-8890"
},
"external_customer_id": "external_id"
}
*/
$bankAccount = new BankAccount();
$bankAccount->setAccountNumber("4417119669820331")
->setAccountNumberType("IBAN")
->setAccountType("SAVINGS")
->setAccountName("Ramraj")
->setCheckType("PERSONAL")
->setAuthType("WEB")
->setBankName("CITI")
->setCountryCode("US")
->setFirstName("Ramraj")
->setLastName("K")
->setBirthDate("1987-08-13")
->setExternalCustomerId(uniqid());
$billingAddress = new \PayPal\Api\Address();
$billingAddress->setLine1("52 N Main St")
->setCity("Johnstown")
->setState("OH")
->setCountryCode("US")
->setPostalCode("43210")
->setPhone("408-334-8890");
$bankAccount->setBillingAddress($billingAddress);
// For Sample Purposes Only.
$request = clone $bankAccount;
// ### Save bank account
// Creates the bank account as a resource
// in the PayPal vault. The response contains
// an 'id' that you can use to refer to it
// in future payments.
// (See bootstrap.php for more on `ApiContext`)
try {
$bankAccount->create($apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Create Bank Account", "Bank Account", null, $request, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Create Bank Account", "Bank Account", $bankAccount->getId(), $request, $bankAccount);
return $bankAccount;
@@ -0,0 +1,56 @@
<?php
// # Create Credit Card Sample
// You can store credit card details securely
// with PayPal. You can then use the returned
// Credit card id to process future payments.
// API used: POST /v1/vault/credit-card
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\CreditCard;
// ### CreditCard
// A resource representing a credit card that is
// to be stored with PayPal.
$card = new CreditCard();
$card->setType("visa")
->setNumber("4917912523797702")
->setExpireMonth("11")
->setExpireYear("2019")
->setCvv2("012")
->setFirstName("Joe")
->setLastName("Shopper");
// ### Additional Information
// Now you can also store the information that could help you connect
// your users with the stored credit cards.
// All these three fields could be used for storing any information that could help merchant to point the card.
// However, Ideally, MerchantId could be used to categorize stores, apps, websites, etc.
// ExternalCardId could be used for uniquely identifying the card per MerchantId. So, combination of "MerchantId" and "ExternalCardId" should be unique.
// ExternalCustomerId could be userId, user email, etc to group multiple cards per user.
$card->setMerchantId("MyStore1");
$card->setExternalCardId("CardNumber123" . uniqid());
$card->setExternalCustomerId("123123-myUser1@something.com");
// For Sample Purposes Only.
$request = clone $card;
// ### Save card
// Creates the credit card as a resource
// in the PayPal vault. The response contains
// an 'id' that you can use to refer to it
// in future payments.
// (See bootstrap.php for more on `ApiContext`)
try {
$card->create($apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Create Credit Card", "Credit Card", null, $request, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Create Credit Card", "Credit Card", $card->getId(), $request, $card);
return $card;
@@ -0,0 +1,23 @@
<?php
// # Delete Bank Account Sample
// This sample code demonstrate how you can
// delete a saved bank account
// API used: /v1/vault/bank-accounts/{<bankAccountId>}
// NOTE: HTTP method used here is DELETE
/** @var \PayPal\Api\BankAccount $card */
$bankAccount = require 'CreateBankAccount.php';
try {
// ### Delete Card
// Lookup and delete a saved credit card.
// (See bootstrap.php for more on `ApiContext`)
$bankAccount->delete($apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Delete Bank Account", "Bank Account", null, null, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Delete Bank Account", "Bank Account", $bankAccount->getId(), null, null);
@@ -0,0 +1,24 @@
<?php
// # Delete CreditCard Sample
// This sample code demonstrate how you can
// delete a saved credit card.
// API used: /v1/vault/credit-card/{<creditCardId>}
// NOTE: HTTP method used here is DELETE
/** @var CreditCard $card */
$card = require 'CreateCreditCard.php';
use PayPal\Api\CreditCard;
try {
// ### Delete Card
// Lookup and delete a saved credit card.
// (See bootstrap.php for more on `ApiContext`)
$card->delete($apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Delete Credit Card", "Credit Card", null, null, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Delete Credit Card", "Credit Card", $card->getId(), null, null);
@@ -0,0 +1,27 @@
<?php
// # Get Bank Account Sample
// The Bank Account resource allows you to
// retrieve previously saved Bank Accounts.
// API called: '/v1/vault/bank-accounts'
// The following code takes you through
// the process of retrieving a saved Bank Account
/** @var \PayPal\Api\BankAccount $bankAccount */
$bankAccount = require 'CreateBankAccount.php';
/// ### Retrieve Bank Account
// (See bootstrap.php for more on `ApiContext`)
try {
$bankAccount = \PayPal\Api\BankAccount::get($bankAccount->getId(), $apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Get Bank Account", "Bank Account", $bankAccount->getId(), null, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Get Bank Account", "Bank Account", $bankAccount->getId(), null, $bankAccount);
return $bankAccount;
@@ -0,0 +1,28 @@
<?php
// # Get Credit Card Sample
// The CreditCard resource allows you to
// retrieve previously saved CreditCards.
// API called: '/v1/vault/credit-card'
// The following code takes you through
// the process of retrieving a saved CreditCard
/** @var CreditCard $card */
$card = require 'CreateCreditCard.php';
$id = $card->getId();
use PayPal\Api\CreditCard;
/// ### Retrieve card
// (See bootstrap.php for more on `ApiContext`)
try {
$card = CreditCard::get($card->getId(), $apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Get Credit Card", "Credit Card", $card->getId(), null, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Get Credit Card", "Credit Card", $card->getId(), null, $card);
return $card;
@@ -0,0 +1,36 @@
<?php
// # List Credit Card Sample
// The CreditCard resource allows you to
// retrieve all previously saved CreditCards.
// API called: '/v1/vault/credit-cards'
// Documentation: https://developer.paypal.com/webapps/developer/docs/api/#list-credit-card-resources
// Creating a Credit Card just in case
/** @var CreditCard $card */
$card = require 'CreateCreditCard.php';
use PayPal\Api\CreditCard;
/// ### List All Credit Cards
// (See bootstrap.php for more on `ApiContext`)
try {
// ### Parameters to Filter
// There are many possible filters that you could apply to it. For complete list, please refere to developer docs at above link.
$params = array(
"sort_by" => "create_time",
"sort_order" => "desc",
"merchant_id" => "MyStore1" // Filtering by MerchantId set during CreateCreditCard.
);
$cards = CreditCard::all($params, $apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("List All Credit Cards", "CreditCardList", null, $params, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("List All Credit Cards", "CreditCardList", null, $params, $cards);
return $card;
@@ -0,0 +1,53 @@
<?php
// # Update Credit Card Sample
// The CreditCard resource allows you to
// update previously saved CreditCards.
// API called: PATCH /v1/vault/credit-cards/<Credit-Card-Id>
// The following code takes you through
// the process of updating a saved CreditCard
/** @var CreditCard $card */
$card = require 'CreateCreditCard.php';
$id = $card->getId();
use PayPal\Api\CreditCard;
use PayPal\Api\Patch;
// ### Patch Object
// You could update a credit card by sending patch requests. Each path object would have a specific detail in the object to be updated.
$pathOperation = new Patch();
$pathOperation->setOp("replace")
->setPath('/expire_month')
->setValue("12");
// ### Another Patch Object
// You could set more than one patch while updating a credit card.
$pathOperation2 = new Patch();
$pathOperation2->setOp('add')
->setPath('/billing_address')
->setValue(json_decode('{
"line1": "111 First Street",
"city": "Saratoga",
"country_code": "US",
"state": "CA",
"postal_code": "95070"
}'));
$pathRequest = new \PayPal\Api\PatchRequest();
$pathRequest->addPatch($pathOperation)
->addPatch($pathOperation2);
/// ### Update Credit Card
// (See bootstrap.php for more on `ApiContext`)
try {
$card = $card->update($pathRequest, $apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Updated Credit Card", "Credit Card", $card->getId(), $pathRequest, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Updated Credit Card", "Credit Card", $card->getId(), $pathRequest, $card);
return $card;