Example #1
0
            "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);
Example #2
0
 public function actionStep2()
 {
     // require_once(Yii::getPathOfAlias('application.components.Paypal') . '/autoload.php');
     $this->layoutPath = Yii::getPathOfAlias('webroot') . "/themes/classic/views/layouts";
     $this->layout = 'nonPrepare';
     $this->checkSession(2);
     $request = Yii::app()->request;
     if ($request->isPostRequest && isset($_POST)) {
         try {
             $this->card_number = $this->getPostFilter('card_number');
             $this->card_holder_name = $this->getPostFilter('card_holder_name');
             $this->expiry_year = $this->getPostFilter('expiry_year');
             $this->expiry_month = $this->getPostFilter('expiry_month');
             $this->cvc = $this->getPostFilter('cvc');
             $this->first_name = $this->getPostFilter('first_name');
             $this->last_name = $this->getPostFilter('last_name');
             $this->bill_city = $this->getPostFilter('bill_city');
             $this->bill_address = $this->getPostFilter('bill_address');
             $this->bill_country = $this->getPostFilter('bill_country');
             $this->bill_postcode = $this->getPostFilter('bill_postcode');
             $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential("AZxYt_EVUMu9xXO0DHBHn4KGUVx6UMIdQKAb7QeCek609Zo3lFCAIfIKs29-T4PL66cSoN6189SfoACj", "ELebkFS3jmn9CNu4PF1t8OWaIsHASMDalHKp9x1dwEo0KmeKo582SfeVIC3CC99tmin7NoJZp00jI2Oc"));
             $addr = new \PayPal\Api\Address();
             $addr->setLine1($this->bill_address);
             $addr->setCity($this->bill_city);
             $addr->setCountryCode($this->bill_country);
             $addr->setPostalCode($this->bill_postcode);
             $addr->setState('OH');
             $card = new \PayPal\Api\CreditCard();
             $card->setNumber($this->card_number);
             $card->setType('visa');
             $card->setExpireMonth($this->expiry_month);
             $card->setExpireYear($this->expiry_year);
             $card->setCvv2($this->cvc);
             $card->setFirstName($this->first_name);
             $card->setLastName($this->last_name);
             $card->setBillingAddress($addr);
             $fi = new \PayPal\Api\FundingInstrument();
             $fi->setCreditCard($card);
             $payer = new \PayPal\Api\Payer();
             $payer->setPaymentMethod('credit_card');
             $payer->setFundingInstruments(array($fi));
             $amount = new \PayPal\Api\Amount();
             $amount->setCurrency('USD');
             $amount->setTotal('0.12');
             $transaction = new \PayPal\Api\Transaction();
             $transaction->setAmount($amount);
             $transaction->setDescription('This is the payment transaction description.');
             $redirectUrls = new \PayPal\Api\RedirectUrls();
             $redirectUrls->setReturnUrl(Yii::app()->createAbsoluteUrl('bookService/step3' . '?success=true'))->setCancelUrl(Yii::app()->createAbsoluteUrl('bookService/step3' . '?success=false'));
             $payment = new \PayPal\Api\Payment();
             $payment->setIntent('sale');
             $payment->setPayer($payer);
             $payment->setTransactions(array($transaction));
             try {
                 $res = $payment->create($apiContext);
             } catch (PayPal\Exception\PayPalConnectionException $e) {
                 echo $e->getData();
                 // This will print a JSON which has specific details about the error.
                 // exit(1);
             }
             $this->nextStep(3);
             if (ERunActions::runBackground()) {
                 $this->SendMailConfirm();
             }
             // die();
             $this->redirectStep(3);
         } catch (exception $e) {
             var_dump($e->getMessage());
         }
     }
     $this->render('step2');
 }
     $_SESSION['shipping_postal_code'] = isset($_SESSION['billing_postal_code']) ? $_SESSION['billing_postal_code'] : '';
     $_SESSION['shipping_country_code'] = isset($_SESSION['billing_country_code']) ? $_SESSION['billing_country_code'] : '';
 }
 $_SESSION['amount'] = isset($_POST['GrandTotal']) ? str_replace(",", "", $_POST['GrandTotal']) : '0.00';
 $_SESSION['subtotal'] = isset($_POST['NetAmount']) ? str_replace(",", "", $_POST['NetAmount']) : '0.00';
 $_SESSION['shipping_amount'] = isset($_POST['ShippingAmount']) && $_POST['ShippingAmount'] != '' ? str_replace(",", "", $_POST['ShippingAmount']) : '0.00';
 $_SESSION['handling_amount'] = isset($_POST['HandlingAmount']) && $_POST['HandlingAmount'] != '' ? str_replace(",", "", $_POST['HandlingAmount']) : '0.00';
 $_SESSION['tax_amount'] = isset($_POST['TaxAmount']) && $_POST['TaxAmount'] != '' ? str_replace(",", "", $_POST['TaxAmount']) : '0.00';
 $_SESSION['billingInfo'] = isset($_POST['billingInfo']) ? $_POST['billingInfo'] : array();
 $_SESSION['shippingInfo'] = isset($_POST['shippingInfo']) ? $_POST['shippingInfo'] : array();
 ##########[ Create Payment ]############
 // Create new PayPal Api Context
 $paypal_rest = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential($config['RESTAPIClient_Id'], $config['RESTAPIClient_Secret']));
 // Add to header
 $paypal_rest->addRequestHeader('PayPal-Partner-Attribution-Id', 'AngellEYE_SP_POS_VT');
 $addr = new \PayPal\Api\Address();
 $addr->setLine1($_SESSION['billing_street1']);
 $addr->setLine2($_SESSION['billing_street2']);
 $addr->setCity($_SESSION['billing_city']);
 $addr->setCountryCode($_SESSION['billing_country_code']);
 $addr->setPostalCode($_SESSION['billing_postal_code']);
 $addr->setState($_SESSION['billing_state']);
 $card = new \PayPal\Api\CreditCard();
 $card->setNumber($_SESSION['cc_number']);
 $card->setType(strtolower($_SESSION['cc_type']));
 $card->setExpireMonth($_SESSION['cc_exp_month']);
 $card->setExpireYear($_SESSION['cc_exp_year']);
 $card->setCvv2($_SESSION['cvv2']);
 $card->setFirstName($_SESSION['billing_first_name']);
 $card->setLastName($_SESSION['billing_last_name']);
 $card->setBillingAddress($addr);