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.
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 thesrcfolder. Another problem seems to be the path:packages/community_store/postfinance/src/CommunityStore/Payment/Methods. Should this not bepackages/postfinance/src/CommunityStore/Payment/Methodsbecause the package name ispostfinanceand notcommunity_store?