php – 如何使用Yii2的PayPal扩展集成yii2中的支付网关
|
如何在yii2中使用paypal扩展.我正在使用此链接
https://github.com/marciocamello/yii2-paypal.
但是没有更多的信息下一步做什么.所以请帮我 谢谢 没有必要使用扩展名.您可以简单地安装 paypal/rest-api-sdk-php软件包并执行以下步骤.1.创建一个组件将PayPal粘贴到Yii2 在@app目录中创建一个组件文件夹.如果您使用的是基本模板,则与webroot文件夹相同;在高级模板中,此文件夹位于您要启用付款的应用中. 创建一个PHP类文件(例如CashMoney),具有以下内容 use yiibaseComponent;
use PayPalRestApiContext;
use PayPalAuthOAuthTokenCredential;
class CashMoney extends Component {
public $client_id;
public $client_secret;
private $apiContext; // paypal's API context
// override Yii's object init()
function init() {
$this->apiContext = new ApiContext(
new OAuthTokenCredential($this->client_id,$this->client_secret)
);
}
public function getContext() {
return $this->apiContext;
}
}
这足以开始.您可以选择稍后添加特定于PayPal的其他配置. 2.用Yii2注册胶水部件 在您的app / config / main.php(或app / config / main-local.php)中,包括以下内容以注册CashMoney组件. 'components' => [
...
'cm' => [ // bad abbreviation of "CashMoney"; not sustainable long-term
'class' => 'app/components/CashMoney',// note: this has to correspond with the newly created folder,else you'd get a ReflectionError
// Next up,we set the public parameters of the class
'client_id' => 'YOUR-CLIENT-ID-FROM-PAYPAL','client_secret' => 'YOUR-CLIENT-SECRET-FROM-PAYPAL',// You may choose to include other configuration options from PayPal
// as they have specified in the documentation
],...
]
现在我们的付款组件注册为CashMoney,我们可以使用Yii :: $app-> cm访问它们.很酷啊 3.进行API调用 到07.01在Yii2, 打开要处理付款的控制器操作,并包括以下内容 use Yii;
...
use PayPalApiCreditCard;
use PayPalExceptionPaypalConnectionException;
class PaymentsController { // or whatever yours is called
...
public function actionMakePayments { // or whatever yours is called
...
$card = new PayPalCreditCard;
$card->setType('visa')
->setNumber('4111111111111111')
->setExpireMonth('06')
->setExpireYear('2018')
->setCvv2('782')
->setFirstName('Richie')
->setLastName('Richardson');
try {
$card->create(Yii::$app->cm->getContext());
// ...and for debugging purposes
echo '<pre>';
var_dump('Success scenario');
echo $card;
} catch (PayPalConnectionException) {
echo '<pre>';
var_dump('Failure scenario');
echo $e;
}
...
}
...
}
预期的输出类似于PayPal文档. 一旦你得到连接,你应该能够执行其他任务. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
