Skip to content

Commit

Permalink
Merge pull request #29 from bibich/button-source
Browse files Browse the repository at this point in the history
Added button source for Thelia
  • Loading branch information
bibich committed Oct 4, 2016
2 parents f4fb1e8 + c44d494 commit ad0034d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Classes/API/PaypalApiManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class PaypalApiManager
/** SandBox API */
const DEFAULT_NVP_3T_API_URL_SANDBOX = 'https://api-3t.sandbox.paypal.com/nvp';

/** Button Source - Identification code for third-party applications */
const BUTTON_SOURCE = 'Thelia_Cart';

/** API Version */
const API_VERSION = '108.0';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ class PaypalNvpOperationsDoExpressCheckoutPayment extends PaypalNvpOperationsBas

/** @var string URL IPN listener */
protected $ipnListenerUrl = null;
/** @var string Thelia_Cart_ECM|Thelia_Cart_ECS */
//protected $buttonSource;

/** @var string Button Source for Thelia_Cart */
protected $buttonSource;

/**
* Constructor
Expand All @@ -73,8 +74,8 @@ public function __construct(
$payerId,
$paymentAction,
$token,
$ipnListenerUrl
//$buttonSource
$ipnListenerUrl,
$buttonSource = null
) {
$this->operationName = 'DoExpressCheckoutPayment';
$this->token = $token;
Expand All @@ -84,7 +85,7 @@ public function __construct(
$this->currencyId = $currencyId;
$this->paymentAction = $paymentAction;
$this->ipnListenerUrl = $ipnListenerUrl;
//$this->buttonSource = $buttonSource;
$this->buttonSource = $buttonSource;
}

/**
Expand All @@ -98,8 +99,10 @@ public function getRequest()
$request .= '&PAYMENTREQUEST_0_AMT=' . $this->amount;
$request .= '&PAYMENTREQUEST_0_CURRENCYCODE=' . $this->currencyId;
$request .= '&PAYMENTREQUEST_0_PAYMENTACTION=' . $this->paymentAction;
if (null !== $this->buttonSource) {
$request .='&BUTTONSOURCE=' . $this->buttonSource;
}

//$request .='&BUTTONSOURCE=' . $this->buttonSource;
return $request;
}
}
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>2.1.1</version>
<version>2.1.2</version>
<author>
<name>Thelia</name>
<email>info@thelia.net</email>
Expand Down
7 changes: 5 additions & 2 deletions Controller/PaypalResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public function ok($order_id)
$payerid,
PaypalApiManager::PAYMENT_TYPE_SALE,
$token,
URL::getInstance()->absoluteUrl("/module/paypal/listen")
URL::getInstance()->absoluteUrl("/module/paypal/listen"),
PaypalApiManager::BUTTON_SOURCE
);

$request = new PaypalNvpMessageSender($doExpressCheckout, $token);
Expand All @@ -116,7 +117,7 @@ public function ok($order_id)
// In case of pending status, log the reason to get usefull information (multi-currency problem, ...)
if (isset($response['ACK']) && $response['ACK'] === "Success" &&
isset($response['PAYMENTINFO_0_PAYMENTSTATUS']) && $response['PAYMENTINFO_0_PAYMENTSTATUS'] === "Pending") {
$this->getTranslator()->trans(
$message = $this->getTranslator()->trans(
"Paypal transaction is pending. Reason: %reason",
[ 'reason' => $response['PAYMENTINFO_0_PENDINGREASON'] ],
Paypal::DOMAIN
Expand Down Expand Up @@ -148,6 +149,8 @@ public function ok($order_id)
} else {
$message = $this->getTranslator()->trans("Failed to find PayerID", [], Paypal::DOMAIN);
}

$this->logger->getLogger()->info("Order [" . $order_id . "] : " . $message);
} catch (RedirectException $ex) {
throw $ex;
} catch (\Exception $ex) {
Expand Down

0 comments on commit ad0034d

Please sign in to comment.