/** * Pay method, used to process payment requests * * @param $payment_detail array Array of parameters for the single requests * Excepts at least the following parameters for each payment to process * [ * paypal_email => string (Paypal email of the receiver) * amount => float (Amount to pay to user) * request_id => int (Unique id of the request paid) * ] * * @return array An array holding the status of the operation; it should have at least a boolean status, a verbose status and an array of messages * [ * status => bool (status of the operation) * verbose_status => string (one between PAYMENT_STATUS_OK and PAYMENT_STATUS_FAIL) * messages => string|array (one or more message describing operation status) * ] * @since 1.0 * @author Antonio La Rocca <*****@*****.**> */ public function pay($payment_detail) { // include required libraries require_once dirname(dirname(__FILE__)) . '/third-party/PayPal/PayPal.php'; // retrieve saved options from panel $stored_options = $this->get_gateway_options(); $currency = get_woocommerce_currency(); if (empty($stored_options['api_username']) || empty($stored_options['api_password']) || empty($stored_options['api_signature'])) { return array('status' => false, 'verbose_status' => YITH_Vendors_Gateway::PAYMENT_STATUS_FAIL, 'messages' => __('Missing required parameters for PayPal configuration', 'yith_wc_product_vendors')); } $PayPalConfig = array('Sandbox' => !($stored_options['sandbox'] == 'no'), 'APIUsername' => $stored_options['api_username'], 'APIPassword' => $stored_options['api_password'], 'APISignature' => $stored_options['api_signature'], 'PrintHeaders' => true, 'LogResults' => false); $PayPal = new PayPal($PayPalConfig); // Prepare request arrays $MPFields = array('emailsubject' => $stored_options['payment_mail_subject'], 'currencycode' => $currency, 'receivertype' => 'EmailAddress'); $MPItems = array(); foreach ($payment_detail as $payment) { $MPItems[] = array('l_email' => $payment['paypal_email'], 'l_amt' => $payment['amount'], 'l_uniqueid' => $payment['request_id']); } $PayPalRequestData = array('MPFields' => $MPFields, 'MPItems' => $MPItems); $PayPalResult = $PayPal->MassPay($PayPalRequestData); $errors = array(); if ($PayPalResult['ACK'] == self::PAYMENT_STATUS_FAIL) { foreach ($PayPalResult['ERRORS'] as $error) { $errors[] = $error['L_LONGMESSAGE']; } } return array('status' => $PayPalResult['ACK'] == self::PAYMENT_STATUS_OK, 'verbose_status' => $PayPalResult['ACK'], 'messages' => $PayPalResult['ACK'] == self::PAYMENT_STATUS_FAIL ? implode("\n", $errors) : __('Payment sent', 'yith_wc_product_vendors')); }
/** * Constructor * * @access public * @param mixed[] $DataArray Array structure providing config data * @return void */ function __construct($DataArray) { parent::__construct($DataArray); $this->XMLNamespace = 'http://svcs.paypal.com/types/ap'; $this->DeviceID = isset($DataArray['DeviceID']) ? $DataArray['DeviceID'] : ''; $this->IPAddress = isset($DataArray['IPAddress']) ? $DataArray['IPAddress'] : $_SERVER['REMOTE_ADDR']; $this->DetailLevel = isset($DataArray['DetailLevel']) ? $DataArray['DetailLevel'] : 'ReturnAll'; $this->ErrorLanguage = isset($DataArray['ErrorLanguage']) ? $DataArray['ErrorLanguage'] : 'en_US'; $this->APISubject = isset($DataArray['APISubject']) ? $DataArray['APISubject'] : ''; $this->DeveloperAccountEmail = isset($DataArray['DeveloperAccountEmail']) ? $DataArray['DeveloperAccountEmail'] : ''; if ($this->Sandbox) { // Sandbox Credentials $this->ApplicationID = isset($DataArray['ApplicationID']) ? $DataArray['ApplicationID'] : ''; $this->APIUsername = isset($DataArray['APIUsername']) && $DataArray['APIUsername'] != '' ? $DataArray['APIUsername'] : ''; $this->APIPassword = isset($DataArray['APIPassword']) && $DataArray['APIPassword'] != '' ? $DataArray['APIPassword'] : ''; $this->APISignature = isset($DataArray['APISignature']) && $DataArray['APISignature'] != '' ? $DataArray['APISignature'] : ''; $this->EndPointURL = isset($DataArray['EndPointURL']) && $DataArray['EndPointURL'] != '' ? $DataArray['EndPointURL'] : 'https://svcs.sandbox.paypal.com/'; } else { // Live Credentials $this->ApplicationID = isset($DataArray['ApplicationID']) ? $DataArray['ApplicationID'] : ''; $this->APIUsername = isset($DataArray['APIUsername']) && $DataArray['APIUsername'] != '' ? $DataArray['APIUsername'] : ''; $this->APIPassword = isset($DataArray['APIPassword']) && $DataArray['APIPassword'] != '' ? $DataArray['APIPassword'] : ''; $this->APISignature = isset($DataArray['APISignature']) && $DataArray['APISignature'] != '' ? $DataArray['APISignature'] : ''; $this->EndPointURL = isset($DataArray['EndPointURL']) && $DataArray['EndPointURL'] != '' ? $DataArray['EndPointURL'] : 'https://svcs.paypal.com/'; } }
public function getPaymant() { $DataArray = []; $PayPalConfig = config('paypal.configPaypal'); $PayPal = new angelleye\PayPal\PayPal($PayPalConfig); $SECFields = array('maxamt' => '200.00', 'returnurl' => 'http://shopping.dev/result', 'cancelurl' => 'http://shopping.dev/account', 'reqconfirmshipping' => '0', 'noshipping' => '1', 'allownote' => '1', 'solutiontype' => 'Sole', 'landingpage' => 'Billing', 'brandname' => 'Angell EYE', 'customerservicenumber' => '555-555-5555', 'giftmessageenable' => '1', 'giftreceiptenable' => '1', 'giftwrapenable' => '1', 'giftwrapname' => 'Box with Ribbon', 'giftwrapamount' => '2.50', 'buyeremailoptionenable' => '1', 'surveyenable' => '1', 'buyerregistrationdate' => '2012-07-14T00:00:00Z'); // Basic array of survey choices. Nothing but the values should go in here. $SurveyChoices = array('Yes', 'No'); $Payments = array(); $Payment = array('amt' => '100.00', 'currencycode' => 'USD', 'itemamt' => '80.00', 'shippingamt' => '15.00', 'insuranceoptionoffered' => '', 'handlingamt' => '', 'taxamt' => '5.00', 'desc' => 'This is a test order.', 'notetext' => 'This is a test note before ever having left the web site.', 'paymentaction' => 'Sale'); $PaymentOrderItems = array(); $Item = array('name' => 'Widget 123', 'desc' => 'Widget 123', 'amt' => '40.00', 'number' => '123', 'qty' => '1', 'itemurl' => 'http://www.angelleye.com/products/123.php'); array_push($PaymentOrderItems, $Item); $Item = array('name' => 'Widget 456', 'desc' => 'Widget 456', 'amt' => '40.00', 'number' => '456', 'qty' => '1', 'itemurl' => 'http://www.angelleye.com/products/456.php', 'itemcategory' => 'Digital'); array_push($PaymentOrderItems, $Item); $Payment['order_items'] = $PaymentOrderItems; array_push($Payments, $Payment); $BuyerDetails = array(); // For shipping options we create an array of all shipping choices similar to how order items works. $ShippingOptions = array(); $Option = array(); array_push($ShippingOptions, $Option); $BillingAgreements = array(); $Item = array('l_billingtype' => 'MerchantInitiatedBilling', 'l_billingagreementdescription' => 'Billing Agreement', 'l_paymenttype' => 'Any'); array_push($BillingAgreements, $Item); $PayPalRequest = array('SECFields' => $SECFields, 'SurveyChoices' => $SurveyChoices, 'BillingAgreements' => $BillingAgreements, 'Payments' => $Payments); $_SESSION['SetExpressCheckoutResult'] = $PayPal->SetExpressCheckout($PayPalRequest); echo '<a href="' . $_SESSION['SetExpressCheckoutResult']['REDIRECTURL'] . '">Click here to continue.</a><br /><br />'; echo '<pre/>'; }