使用(omnipay payum和symfony)集成支付网关2checkout

时间:2015-02-10 12:39:02

标签: php symfony omnipay 2checkout payum

我正在尝试使用payumbundle设置2checkout,我似乎无法理解如何设置config.yml,然后了解如何向2checkout发送信息。

在此之前我已经与Payum成功设置了PayPal快速结账,我对Payum很熟悉(仍在学习Payum)

这是我到目前为止所做的工作

我已经安装了omnipay 2checkout软件包

composer require "payum/omnipay-bridge" "omnipay/2checkout"

因为我似乎无法在线找到2checkout的任何示例,而我发现的最接近的是条纹,所以看看example 这是我的config.yml

payum:
    security:
        .....
    contexts:
        paypal:
            paypal_express_checkout_nvp:
                username: ....
                password: ....
                signature: ....
                sandbox: true

        2checkout:
            omnipay:
                type: TwoCheckout
                options:
                    apiKey: ....
                    pri: ....
                    act: ....
                    testMode: true

这里出现了我的第一个问题

Q1:我如何知道在config.yml中为不同的网关添加哪些信息

现在转到我的操作中的代码,该代码应该将信息发送到2checkout并将数据添加到数据库。

$paymentName = 'TwoCheckout';

$storage = $this->get('payum')->getStorage('ClickTeck\featuresBundle\Entity\Orders');
$paymentDetails = $storage->create();

// insert order into database
$paymentDetails->setClientFname('First');
$paymentDetails->setClientLname('Last');
$paymentDetails->setClientPhone('111-111-111');
$paymentDetails->setClientEmail('xyz@abc.com');
$paymentDetails->setInvoiceId('123');
$paymentDetails->setNumber('456');
$paymentDetails->setDescription('This is description');
$paymentDetails->setCurrencyCode('USD');
$paymentDetails->setTotalAmount('20');
$paymentDetails->setClientId($clientID);
$paymentDetails->setPaymentOption($paymentName);

$storage->update($paymentDetails);


$paymentDetails['amount'] = 20;
$paymentDetails["currency"] = 'USD';
$paymentDetails["description"] = "This is description";

$storage->update($paymentDetails);

$captureToken = $this->get('payum.security.token_factory')->createCaptureToken(
    $paymentName,
    $paymentDetails,
    'payment_done' // the route to redirect after capture;
);


return $this->redirect($captureToken->getTargetUrl());

我正在使用我用于PayPal的相同实体和paypal payum在数据库的details列中添加数据但是对于2checkout它没有添加任何内容以获取详细信息并提供错误Integrity constraint violation细节不应该是空的,所以这是我的第二个问题

Q2:我们不能将同一个实体用于不同的付款方式吗?或者每种付款方式都应该有自己的实体?如果我们可以使用相同的实体,那么为什么payum不会为details列生成任何内容。我在这里做错了什么

如果有人可以帮助我,我将非常感激,我需要看一个例子,而不仅仅是关于如何集成2checkout的解释。然而,也将理解解释。

更新

这是我在我的操作中更新的代码,正在准备付款,这会被添加到数据库,但交易失败

$paymentName = 'TwoCheckout';
$storage = $this->get('payum')->getStorage('ClickTeck\featuresBundle\Entity\Orders');
/** @var Orders $details */

$details = $storage->create();

// insert order into database
$details->setClientFname($form->get('client_fname')->getData());
$details->setClientLname($form->get('client_lname')->getData());
$details->setClientPhone($form->get('client_phone')->getData());
$details->setClientEmail($form->get('client_email')->getData());
$details->setInvoiceId('123');
$details->setNumber('456');
$details->setDescription('This is description');

//change currency to dynamic before live
$details->setCurrencyCode('USD');
$details->setTotalAmount($cartTotal.".00");
$details->setClientId($clientID);
$details->setPaymentOption($paymentName);



$details["sid"] = '201308888';
$details["cart_order_id"] = '123456';
$details["merchant_order_id"] = '789';
$details["total"] = $cartTotal.".00";

$details["amount"] = $cartTotal.".00";
$details["tco_currency"] = 'USD';
$details['fixed'] = 'Y';
$details['skip_landing'] = 1;
$details['card_holder_name'] = 'Hold Name';
$details['street_address'] = 'Address 1';
$details['street_address2'] = 'Address 2';
$details['city'] = 'City';
$details['state'] = 'State';
$details['zip'] = '08610';
$details['country'] = 'USA';
$details['phone'] = '111-111-111';
$details['email'] = 'dummy@xyz.com';

$details["name"] = 'a name';
$details["description"] = 'a description';
$details['card'] = new SensitiveValue(array(
    'number' => $form->get('cardNumber')->getData(),
    'cvv' => $form->get('cvv')->getData(),
    'expiryMonth' => $form->get('expiryMonth')->getData(),
    'expiryYear' => $form->get('expiryYear')->getData(),
    'firstName' => $form->get('client_fname')->getData(),
));

$storage->update($details);
$captureToken = $this->get('payum.security.token_factory')->createCaptureToken(
    $paymentName,
    $details,
    'payment_done' // the route to redirect after capture;
);
$details["returnUrl"] = $captureToken->getTargetUrl();
//return $this->redirect($captureToken->getTargetUrl());
return $this->forward('PayumBundle:Capture:do', array(
    'payum_token' => $captureToken,
));

这是我看到的回应,我似乎无法理解为什么会失败

{"status":"failed","order":{"total_amount":500,"currency_code":"USD","details":{"sid":"201308888","cart_order_id":"123456","merchant_order_id":"789","total":"500.00","amount":"500.00","tco_currency":"USD","fixed":"Y","skip_landing":1,"card_holder_name":"Hold Name","street_address":"Address 1","street_address2":"Address 2","city":"city","state":"State","zip":"08610","country":"USA","phone":"111-111-111","email":"dummy@xyz.com","name":"a name","description":"a description","card":[],"returnUrl":"http:\/\/127.0.0.1:8000\/payment\/capture\/mjIo0HsxKQ1-DRISYUZ6fMZLUmOXD0-cPiOheqRqpH8","clientIp":"127.0.0.1","_reference":null,"_status":"failed","_status_code":null,"_status_message":null}}}

1 个答案:

答案 0 :(得分:0)

  

Q1:我如何知道在config.yml中为不同的网关添加哪些信息

Payum的支付工厂提供有关可能选项的信息。其默认值和所需值。您必须调用$ factory-> createConfig()并查找payum.required_optionspayum.default_optionsexample)。在PayumBundle中的东西更加简单。该软件包提供了工厂,可以扩展容器配置和可能的选项因此,他们将通过Symfony的标准配置验证器进行验证。

要了解您必须在Omnipay网关中传递哪些选项,您必须查看该网关setters \ getters方法(example)。例如,网关具有方法setTestMode,要在PayumBundle中配置它,您必须定义选项testModeThis is how个选项已转换为设置者调用。

2Checkout我猜必须这样配置。

payum:
    contexts:
        2checkout:
            omnipay:
                type: TwoCheckout
                options:
                    accountNumber: ....
                    secretWord: ....
                    testMode: true
  

Q2:我们不能将同一个实体用于不同的付款方式吗?或者每种付款方式都应该有自己的实体?如果我们可以使用相同的实体,那么为什么payum不会为详细信息列生成任何内容。我在这做错了什么

从Payum的角度来看,您可以使用相同的实体\型号来存储不同的付款。由于我从未使用过Omnipay和2Checkout网关,所以我在这里帮不了多忙。