Create PostFinance payment request

纵然是瞬间 提交于 2020-08-08 05:15:03

问题


PHP: Can anyone help me how to create a payment request using wysow repository?

I found this link, but there weren't any solutions. I am am using concrete5's Community Store and am trying to create a PostFinance payment package/addon. I have the following code in /packages/community_store_postfinance/src/CommunityStore/Payment/Methods/CommunityStorePostfinance/CommunityStorePostfinancePaymentMethod.php file (which is a copy of the example in GitHub):

$passphrase = new Passphrase($shaInSecret);
$shaComposer = new AllParametersShaComposer($passphrase);

$ecommercePaymentRequest = new EcommercePaymentRequest($shaComposer);

// Set various params:
$ecommercePaymentRequest->setPspid($postfinancePsid);
$ecommercePaymentRequest->setOrderid($custmerOrder->getOrderId());
$ecommercePaymentRequest->setPostFinanceUri(EcommercePaymentRequest::TEST);

$ecommercePaymentRequest->setAmount((Int)$amount);
$ecommercePaymentRequest->setCurrency('CHF');
$ecommercePaymentRequest->setCustomername($customerName);
$ecommercePaymentRequest->setOwnerAddress($address);
$ecommercePaymentRequest->validate();

$formGenerator = new SimpleFormGenerator;
$paymentForm = $formGenerator->render($ecommercePaymentRequest);
// I then pass this to my redirect view
$this->set('paymentForm', $paymentForm);

I have debugged and the form is being created and looks correct, as is required by PostFinance and I get redirected the the PostFinance payment confirmation page, but none of the details have been passed to PostFinance. I am just wondering whether I missed something or if I should be adding something else in the request for the form to go through automatically? Any insights would be appreciated. Thanks.


回答1:


A value set by $this->set() will be lost, when redirecting. You would need to set it into the session. Or you do the form generating in the method where you want to redirect to (you could call the code from above in this method, but instead of a redirect you need to return the generated form).

But I think there are other problems: $this->set() is normally a method from a controller (page-, block- etc. controller). But you are using it in a class from the src folder. Another problem seems to be the path: packages/community_store/postfinance/src/CommunityStore/Payment/Methods. Should this not be packages/postfinance/src/CommunityStore/Payment/Methods because the package name is postfinance and not community_store?




回答2:


Just in case anyone else wanted to know my solution, it was a dumb error on my part as all I had to do was return or echo $paymentForm; This solved my problem and successfully sent the form to PostFinance.

Although now I have the problem of not being able to get the PostFinance backend generated signature to match, PostFinance Signature not matching



来源:https://stackoverflow.com/questions/63034791/create-postfinance-payment-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!