PHP code example of phpcommerce / ratepay

1. Go to this page and download the library: Download phpcommerce/ratepay library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phpcommerce / ratepay example snippets


use Doctrine\Common\Annotations\AnnotationRegistry;
use GuzzleHttp\Client;
use PHPCommerce\Vendor\RatePAY\Service\Payment\Exception\RatePAYException;
use PHPCommerce\Vendor\RatePAY\Service\Payment\GatewayClientImpl;
use PHPCommerce\Vendor\RatePAY\Service\Payment\RatepayBrokerImpl;
use PHPCommerce\Vendor\RatePAY\Service\Payment\RatepayConfiguration;
use PHPCommerce\Vendor\RatePAY\Service\Payment\RatepayCredential;
use PHPCommerce\Vendor\RatePAY\Service\Payment\Type\AddressType;
use PHPCommerce\Vendor\RatePAY\Service\Payment\Type\ContactsType;
use PHPCommerce\Vendor\RatePAY\Service\Payment\Type\CustomerType;
use PHPCommerce\Vendor\RatePAY\Service\Payment\Type\ExternalType;
use PHPCommerce\Vendor\RatePAY\Service\Payment\Type\PaymentType;
use PHPCommerce\Vendor\RatePAY\Service\Payment\Type\RequestHeadType;
use PHPCommerce\Vendor\RatePAY\Service\Payment\Type\PhoneType;
use PHPCommerce\Vendor\RatePAY\Service\Payment\Type\RequestType;
use PHPCommerce\Vendor\RatePAY\Service\Payment\Type\ShoppingBasketItemType;
use PHPCommerce\Vendor\RatePAY\Service\Payment\Type\ShoppingBasketType;
use PHPCommerce\Vendor\RatePAY\Service\Payment\DeviceFingerprintSnippetGenerator;

     ->setGender(CustomerType::GENDER_MALE)
            ->setDateOfBirth(new DateTime("1985-01-01"))
            ->setIpAddress("123.123.123.123")
            ->setCustomerAllowCreditInquiry(true)
            ->setContacts(
                (new ContactsType())
                    ->setEmail("[email protected]")
                    ->setPhone(
                        (new PhoneType ())
                            ->setAreaCode("040")
                            ->setDirectDial("1234567890")
                    )
            )
            ->setAddresses([
                (new AddressType())
                    ->setType(AddressType::ADDRESS_TYPE_BILLING)
                    ->setFirstName("Max")
                    ->setLastName("Mustermann")
                    ->setStreet("Musterstraße")
                    ->setStreetNumber("77")
                    ->setZipCode("12345")
                    ->setCity("Musterstadt")
                    ->setCountryCode('DE')
            ])
        )
        ->shoppingBasket(
            (new ShoppingBasketType())
                ->setAmount(100)
                ->setCurrency('EUR')
                ->setItems([
                    (new ShoppingBasketItemType())
                        ->setArticleNumber("123")
                        ->setQuantity("1")
                        ->setUnitPriceGross(100)
                        ->setItem("Artcile 1")
                ])
        )
        ->payment(
            (new PaymentType())
                ->setMethod(PaymentType::METHOD_INVOICE)
                ->setCurrency(PaymentType::CURRENCY_EUR)
                ->setAmount(100)
        )
        ->build();

    $res = $ratepayBroker->paymentRequest($transactionId, $paymentRequest);

    /** @var PaymentRequestResponseType $paymentRequestResponse */
    $paymentRequestResponse = $res->getContent();

    $descriptor = $paymentRequestResponse->getPayment()->getDescriptor();
    
    // save $descriptor for your reference
			
    $ratepayBroker->paymentConfirm($transactionId);

} catch (RatePAYException $e) {
    $message = ($e->getCustomerMessage() != "") ?
        $e->getCustomerMessage() : "The RatePAY transaction could not be processed";

    echo $message;
}

    $paymentChange = $ratepayBroker->getRequestBuilder()
        ->shoppingBasket(
            (new ShoppingBasketType())
                ->setAmount(1000)
                ->setCurrency('EUR')
                ->setItems([
                    (new ShoppingBasketItemType())
                        ->setArticleNumber("123")
                        ->setQuantity("10")
                        ->setUnitPriceGross(100)
                        ->setItem("Article 1")
                ])
        )
        ->build();

    $res = $ratepayBroker->paymentChange($transactionId, OperationType::OPERATION_SUBTYPE_CHANGE_ORDER, $paymentChange);

    $confirmationDeliver = $ratepayBroker->getRequestBuilder()
        ->shoppingBasket(
            (new ShoppingBasketType())
                ->setAmount(1000)
                ->setCurrency('EUR')
                ->setItems([
                    (new ShoppingBasketItemType())
                        ->setArticleNumber("123")
                        ->setQuantity("10")
                        ->setUnitPriceGross(100)
                        ->setItem("Article 1")
                ])
        )
        ->build();

    $res = $ratepayBroker->confirmationDeliver($transactionId, $confirmationDeliver);

AnnotationRegistry::registerAutoloadNamespace(
    'JMS\Serializer\Annotation',
    __DIR__ . "/vendor/jms/serializer/src");